Source

savReaderWriter / savReaderWriter / doc_tests / test_SavHeaderReader_unicode.txt

##############################################################################
## Print a Python dictionary of the SPSS dictionary (aka header information)
##############################################################################

>>> from __future__ import print_function
>>> from savReaderWriter import *

>>> savFileName = "../savReaderWriter/test_data/greetings.sav"
>>> with SavHeaderReader(savFileName, ioUtf8=True) as header: # doctest: +ELLIPSIS
...     metadata = header.dataDictionary()

>>> thai = u'\u0e2a\u0e27\u0e31\u0e2a\u0e14\u0e35'
>>> arabic = (u'\u0627\u0644\u0633\u0644\u0627\u0645 '+ 
...           u'\u0639\u0644\u064a\u0643\u0645')
>>> desired = \
... {u'alignments': {u'Bondjo\xfb': u'left',
...                  u'greeting': u'left',
...                  u'line': u'left'},
...  u'caseWeightVar': u'',
...  u'columnWidths': {u'Bondjo\xfb': 20, u'greeting': 50, u'line': 8},
...  u'fileAttributes': {},
...  u'fileLabel': u"File created by user 'Administrator' at Thu Jan 17 16:35:14 2013",
...  u'formats': {u'Bondjo\xfb': u'A20', u'greeting': u'A50', u'line': u'F8.2'},
...  u'measureLevels': {u'Bondjo\xfb': u'unknown',
...                     u'greeting': u'unknown',
...                     u'line': u'unknown'},
...  u'missingValues': {u'Bondjo\xfb': {u'values': [u'\xa1Hola! ']},
...                     u'greeting': {},
...                     u'line': {u'lower': 0.0, u'upper': 9.0}},
...  u'multRespDefs': {},
...  u'valueLabels': {u'Bondjo\xfb': {u'Thai                ': thai}},
...  u'varAttributes': {},
...  u'varLabels': {u'Bondjo\xfb': u'',
...                 u'greeting': arabic,
...                 u'line': u''},
...  u'varNames': [u'line', u'Bondjo\xfb', u'greeting'],
...  u'varRoles': {u'Bondjo\xfb': u'input',
...                u'greeting': u'input',
...                u'line': u'input'},
...  u'varSets': {},
...  u'varTypes': {u'Bondjo\xfb': 20, u'greeting': 50, u'line': 0}}
>>> desired == metadata
True
>>> for k, v in desired.items():
...     print("%s ---> %s" % (k.upper(), v == metadata[k]))
...     if v != metadata[k]:
...         print(v)
...         print(metadata[k])
VALUELABELS ---> True
CASEWEIGHTVAR ---> True
VARSETS ---> True
VARATTRIBUTES ---> True
VARROLES ---> True
MEASURELEVELS ---> True
VARTYPES ---> True
VARNAMES ---> True
VARLABELS ---> True
FORMATS ---> True
MULTRESPDEFS ---> True
COLUMNWIDTHS ---> True
MISSINGVALUES ---> True
ALIGNMENTS ---> True
FILELABEL ---> True
FILEATTRIBUTES ---> True