Source

savReaderWriter / savReaderWriter / doc_tests / test_SavHeaderReader_unicode.txt

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

>>> import sys
>>> sys.stdout.write('<skipline> '); from savReaderWriter import * # doctest: +ELLIPSIS
<skipline> ...


>>> savFileName = "../savReaderWriter/test_data/greetings.sav"
>>> with SavHeaderReader(savFileName, ioUtf8=True) as spssDict: # doctest: +ELLIPSIS
...     really = spssDict.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 == really
True
>>> for k, v in desired.items():
...     "%s ---> %s" % (k.upper(), v == really[k])
...     if v != really[k]:
...         print v
...         print really[k]
u'VALUELABELS ---> True'
u'CASEWEIGHTVAR ---> True'
u'VARSETS ---> True'
u'VARATTRIBUTES ---> True'
u'VARROLES ---> True'
u'MEASURELEVELS ---> True'
u'VARTYPES ---> True'
u'VARNAMES ---> True'
u'VARLABELS ---> True'
u'FORMATS ---> True'
u'MULTRESPDEFS ---> True'
u'COLUMNWIDTHS ---> True'
u'MISSINGVALUES ---> True'
u'ALIGNMENTS ---> True'
u'FILELABEL ---> True'
u'FILEATTRIBUTES ---> True'