Commits

AJ R  committed fb74f0a

Modified tox.ini, with skipsdist=True all unittests pass for py27, py33 and pypy

  • Participants
  • Parent commits ee15fef

Comments (0)

Files changed (18)

File savReaderWriter/doc_tests/runtests.py

-import nose
-result = nose.run()

File savReaderWriter/doc_tests/test_SPSSIOError.txt

-##############################################################################
-## Check if the custom error class does its job
-##############################################################################
-
->>> import os, tempfile, sys
->>> from savReaderWriter import *
-
->>> badSavFile = os.path.join(tempfile.gettempdir(), "yields_error.sav")
->>> with open(badSavFile, "wb") as f:
-...     line = 79 * "*" + "\n"
-...     for i in range(1000):
-...         f.write(line)
->>> with SavReader(badSavFile) as reader:
-...     for line in reader:
-...        pass   # doctest:+ELLIPSIS
-Traceback (most recent call last):
-  File "<stdin>", line 1, in ?
-SPSSIOError: Problem opening file '...yields_error.sav' in mode 'rb' [SPSS_INVALID_FILE]
-
-

File savReaderWriter/doc_tests/test_SavHeaderReader_dictionary.txt

-##############################################################################
-## Print a Python dictionary of the SPSS dictionary (aka header information)
-##############################################################################
-
->>> from savReaderWriter import *
-
->>> savFileName = "../savReaderWriter/test_data/Employee data.sav"
->>> with SavHeaderReader(savFileName) as spssDict: # doctest: +ELLIPSIS
-...     metadata = spssDict.dataDictionary()
->>> desired = \
-...     {'alignments': {'bdate': 'right',
-...                     'educ': 'right',
-...                     'gender': 'left',
-...                     'id': 'right',
-...                     'jobcat': 'right',
-...                     'jobtime': 'right',
-...                     'minority': 'right',
-...                     'prevexp': 'right',
-...                     'salary': 'right',
-...                     'salbegin': 'right'},
-...      'caseWeightVar': '',
-...      'columnWidths': {'bdate': 13,
-...                       'educ': 8,
-...                       'gender': 1,
-...                       'id': 8,
-...                       'jobcat': 8,
-...                       'jobtime': 8,
-...                       'minority': 8,
-...                       'prevexp': 8,
-...                       'salary': 8,
-...                       'salbegin': 8},
-...      'fileAttributes': {},
-...      'fileLabel': '05.00.00',
-...      'formats': {'bdate': 'ADATE10',
-...                  'educ': 'F2',
-...                  'gender': 'A1',
-...                  'id': 'F4',
-...                  'jobcat': 'F1',
-...                  'jobtime': 'F2',
-...                  'minority': 'F1',
-...                  'prevexp': 'F6',
-...                  'salary': 'DOLLAR8',
-...                  'salbegin': 'DOLLAR8'},
-...      'measureLevels': {'bdate': 'ratio',
-...                        'educ': 'ordinal',
-...                        'gender': 'nominal',
-...                        'id': 'ratio',
-...                        'jobcat': 'ordinal',
-...                        'jobtime': 'ratio',
-...                        'minority': 'ordinal',
-...                        'prevexp': 'ratio',
-...                        'salary': 'ratio',
-...                        'salbegin': 'ratio'},
-...      'missingValues': {'bdate': {},
-...                        'educ': {'values': [0.0]},
-...                        'gender': {},
-...                        'id': {},
-...                        'jobcat': {'values': [0.0]},
-...                        'jobtime': {'values': [0.0]},
-...                        'minority': {'values': [9.0]},
-...                        'prevexp': {},
-...                        'salary': {'values': [0.0]},
-...                        'salbegin': {'values': [0.0]}},
-...      'multRespDefs': {},
-...      'valueLabels': {'educ': {0.0: '0 (Missing)',
-...                               8.0: '8',
-...                               12.0: '12',
-...                               14.0: '14',
-...                               15.0: '15',
-...                               16.0: '16',
-...                               17.0: '17',
-...                               18.0: '18',
-...                               19.0: '19',
-...                               20.0: '20',
-...                               21.0: '21'},
-...                      'gender': {'f': 'Female', 'm': 'Male'},
-...                      'jobcat': {0.0: '0 (Missing)',
-...                                 1.0: 'Clerical',
-...                                 2.0: 'Custodial',
-...                                 3.0: 'Manager'},
-...                      'jobtime': {0.0: 'missing'},
-...                      'minority': {0.0: 'No', 1.0: 'Yes', 9.0: '9 (Missing)'},
-...                      'prevexp': {0.0: 'missing'},
-...                      'salary': {0.0: 'missing'},
-...                      'salbegin': {0.0: 'missing'}},
-...      'varAttributes': {},
-...      'varLabels': {'bdate': 'Date of Birth',
-...                    'educ': 'Educational Level (years)',
-...                    'gender': 'Gender',
-...                    'id': 'Employee Code',
-...                    'jobcat': 'Employment Category',
-...                    'jobtime': 'Months since Hire',
-...                    'minority': 'Minority Classification',
-...                    'prevexp': 'Previous Experience (months)',
-...                    'salary': 'Current Salary',
-...                    'salbegin': 'Beginning Salary'},
-...      'varNames': ['id',
-...                   'gender',
-...                   'bdate',
-...                   'educ',
-...                   'jobcat',
-...                   'salary',
-...                   'salbegin',
-...                   'jobtime',
-...                   'prevexp',
-...                   'minority'],
-...      'varRoles': {'bdate': 'input',
-...                   'educ': 'input',
-...                   'gender': 'input',
-...                   'id': 'input',
-...                   'jobcat': 'input',
-...                   'jobtime': 'input',
-...                   'minority': 'input',
-...                   'prevexp': 'input',
-...                   'salary': 'input',
-...                   'salbegin': 'input'},
-...      'varSets': {'DEMOGR': ['gender', 'minority', 'educ'],
-...                  'SALARY': ['salbegin', 'salary']},
-...      'varTypes': {'bdate': 0,
-...                   'educ': 0,
-...                   'gender': 1,
-...                   'id': 0,
-...                   'jobcat': 0,
-...                   'jobtime': 0,
-...                   'minority': 0,
-...                   'prevexp': 0,
-...                   'salary': 0,
-...                   'salbegin': 0}}
->>> desired == metadata
-True

File savReaderWriter/doc_tests/test_SavHeaderReader_report1.txt

-##############################################################################
-## Print a report of the header information
-##############################################################################
-
->>> from __future__ import print_function
->>> from savReaderWriter import *
-
->>> savFileName = "../savReaderWriter/test_data/spssio_test.sav"
->>> with SavHeaderReader(savFileName) as header: # doctest: +ELLIPSIS
-...     print(str(header))
-#ALIGNMENTS
-AGE2 -- right
-AGE3 -- right
-Age -- left
-AvgIncome -- right
-DATE_ -- left
-ID -- left
-Income1 -- right
-Income2 -- right
-Income3 -- center
-MONTH_ -- right
-MaxIncome -- right
-QUARTER_ -- right
-Region -- left
-SEX -- right
-V1 -- right
-V2 -- right
-V3 -- right
-YEAR_ -- right
-aLongStringVar -- left
-aShortStringVar -- left
-someDate -- right
-weightVar -- right
-#CASEWEIGHTVAR
-weightVar
-#COLUMNWIDTHS
-AGE2 -- 10
-AGE3 -- 10
-Age -- 10
-AvgIncome -- 11
-DATE_ -- 10
-ID -- 10
-Income1 -- 14
-Income2 -- 14
-Income3 -- 15
-MONTH_ -- 8
-MaxIncome -- 11
-QUARTER_ -- 10
-Region -- 10
-SEX -- 10
-V1 -- 10
-V2 -- 10
-V3 -- 10
-YEAR_ -- 10
-aLongStringVar -- 26
-aShortStringVar -- 17
-someDate -- 13
-weightVar -- 11
-#FILEATTRIBUTES
-$VariableView2[01] -- name
-$VariableView2[02] -- type
-$VariableView2[03] -- width
-$VariableView2[04] -- decimals
-$VariableView2[05] -- label
-$VariableView2[06] -- values
-$VariableView2[07] -- missing
-$VariableView2[08] -- columns
-$VariableView2[09] -- alignment
-$VariableView2[10] -- measure
-$VariableView2[11] -- role
-$VariableView2[12] -- @Formula
-$VariableView2[13] -- @DerivedFrom
-$VariableView2[14] -- @Notes
-VersionNumber -- 1
-#FILELABEL
-This is a file label
-#FORMATS
-AGE2 -- F8.2
-AGE3 -- F8.2
-Age -- F3
-AvgIncome -- F8.2
-DATE_ -- A8
-ID -- N6
-Income1 -- F8.2
-Income2 -- F8.2
-Income3 -- F8.2
-MONTH_ -- F2
-MaxIncome -- F8.2
-QUARTER_ -- F1
-Region -- F8.2
-SEX -- F8.2
-V1 -- F8.2
-V2 -- F8.2
-V3 -- F8.2
-YEAR_ -- F8
-aLongStringVar -- A100
-aShortStringVar -- A1
-someDate -- ADATE40
-weightVar -- F8.2
-#MEASURELEVELS
-AGE2 -- ratio
-AGE3 -- ratio
-Age -- ratio
-AvgIncome -- ratio
-DATE_ -- nominal
-ID -- nominal
-Income1 -- ratio
-Income2 -- ratio
-Income3 -- ratio
-MONTH_ -- ordinal
-MaxIncome -- ratio
-QUARTER_ -- ordinal
-Region -- nominal
-SEX -- nominal
-V1 -- nominal
-V2 -- nominal
-V3 -- nominal
-YEAR_ -- ordinal
-aLongStringVar -- nominal
-aShortStringVar -- nominal
-someDate -- ratio
-weightVar -- nominal
-#MISSINGVALUES
-Age: lower -- 0.0
-Age: upper -- 18.0
-Income1: lower -- -1.797...+308
-Income1: upper -- -1.0
-Income2: lower -- -1.797...+308
-Income2: upper -- -1.0
-Income2: value -- 999.0
-Income3: values -- 999.0, 888.0, 777.0
-aShortStringVar: values -- x, y
-#MULTRESPDEFS
-V: countedValue -- 1
-V: label -- 
-V: setType -- D
-V: varNames -- V1, V2, V3
-ages: label -- the ages
-ages: setType -- C
-ages: varNames -- Age, AGE2, AGE3
-incomes: label -- three kinds of income
-incomes: setType -- C
-incomes: varNames -- Income1, Income2, Income3, Age, AGE2, AGE3
-#VALUELABELS
-Age: 27.0 -- 27 y.o. 
-Age: 34.0 -- 34 y.o.
-Age: 50.0 -- 50 y.o.
-aShortStringVar: x -- someValue label
-#VARATTRIBUTES
-AvgIncome: DerivedFrom[1] -- Income1
-AvgIncome: DerivedFrom[2] -- Income2
-AvgIncome: DerivedFrom[3] -- Income3
-AvgIncome: Formula -- mean(Income1, Income2, Income3)
-MaxIncome: DerivedFrom[1] -- Income1
-MaxIncome: DerivedFrom[2] -- Income2
-MaxIncome: DerivedFrom[3] -- Income3
-MaxIncome: Formula -- max(Income1, Income2, Income3)
-#VARLABELS
-AGE2 -- 
-AGE3 -- 
-Age -- How old are you?
-AvgIncome -- 
-DATE_ -- Date.  Format:  "MMM YYYY"              
-ID -- 
-Income1 -- 
-Income2 -- 
-Income3 -- 
-MONTH_ -- MONTH, period 12
-MaxIncome -- 
-QUARTER_ -- QUARTER, period 4
-Region -- What region do you live
-SEX -- 
-V1 -- 
-V2 -- 
-V3 -- 
-YEAR_ -- YEAR, not periodic
-aLongStringVar -- Some mysterious long stringVar
-aShortStringVar -- Some mysterious short stringVar
-someDate -- 
-weightVar -- 
-#VARNAMES
-ID
-Age
-Region
-Income1
-Income2
-Income3
-AvgIncome
-MaxIncome
-AGE2
-AGE3
-SEX
-V1
-V2
-V3
-someDate
-aShortStringVar
-aLongStringVar
-weightVar
-YEAR_
-QUARTER_
-MONTH_
-DATE_
-#VARROLES
-AGE2 -- input
-AGE3 -- input
-Age -- input
-AvgIncome -- input
-DATE_ -- input
-ID -- input
-Income1 -- target
-Income2 -- target
-Income3 -- target
-MONTH_ -- input
-MaxIncome -- input
-QUARTER_ -- input
-Region -- partition
-SEX -- input
-V1 -- input
-V2 -- input
-V3 -- input
-YEAR_ -- input
-aLongStringVar -- input
-aShortStringVar -- input
-someDate -- input
-weightVar -- input
-#VARSETS
-#VARTYPES
-AGE2 -- 0
-AGE3 -- 0
-Age -- 0
-AvgIncome -- 0
-DATE_ -- 8
-ID -- 0
-Income1 -- 0
-Income2 -- 0
-Income3 -- 0
-MONTH_ -- 0
-MaxIncome -- 0
-QUARTER_ -- 0
-Region -- 0
-SEX -- 0
-V1 -- 0
-V2 -- 0
-V3 -- 0
-YEAR_ -- 0
-aLongStringVar -- 100
-aShortStringVar -- 1
-someDate -- 0
-weightVar -- 0

File savReaderWriter/doc_tests/test_SavHeaderReader_type7.txt

-##############################################################################
-## Query type 7 record information of a file
-##############################################################################
-
->>> from savReaderWriter import *
-
-# e.g. Record subtype 3, which contains 'Release information' is present (True)
-# This file contains release info, but no date variable info, etc. etc.
->>> savFileName = "../savReaderWriter/test_data/Employee data.sav"
->>> with SavHeaderReader(savFileName) as header:
-...    type7info = header.queryType7
->>> desired = \
-... {3: ('Release information', True),
-...  4: ('Floating point constants including the system missing value', True),
-...  5: ('Variable set definitions', True),
-...  6: ('Date variable information', False),
-...  7: ('Multiple-response set definitions', False),
-...  8: ('Data Entry for Windows (DEW) information', False),
-... 10: ('TextSmart information', False),
-... 11: ('Measurement level, column width, and alignment for each variable',
-...       True)}
->>> desired == type7info
-True

File 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

File savReaderWriter/doc_tests/test_SavReader_dates_elaborate.txt

-##############################################################################
-## Read a file containg all the supported date formats
-##############################################################################
-
->>> from __future__ import print_function
->>> import tempfile
->>> import os
->>> from savReaderWriter import *
-
-## first, create a test file
->>> varNames = ['var_datetime', 'var_wkyr', 'var_date', 'var_qyr', 'var_edate',
-...             'var_sdate', 'var_dtime', 'var_jdate', 'var_month', 'var_moyr',
-...             'var_time', 'var_adate', 'var_wkday']
->>> varTypes = {v : 0 for v in varNames}
->>> spssfmts = ['DATETIME40', 'WKYR10', 'DATE10', 'QYR10', 'EDATE10',
-...             'SDATE10', 'DTIME10', 'JDATE10', 'MONTH10', 'MOYR10',
-...             'TIME10', 'ADATE10', 'WKDAY10']
->>> formats = dict(zip(varNames, spssfmts))
->>> savFileName = os.path.join(tempfile.gettempdir(), "test_dates.sav")
->>> records = [['2010-08-11'] * len(varNames), ['1910-01-12'] * len(varNames),
-...            [""] * len(varNames), [None] * len(varNames)]
-
->>> with SavWriter(savFileName, varNames, varTypes, formats=formats) as writer:
-...     for record in records:
-...         for pos, value in enumerate(record):
-...             record[pos] = writer.spssDateTime(record[pos], "%Y-%m-%d")
-...         writer.writerow(record)
-
- 
-## second, read the file back in
-# these are the destination formats that are used internally by savReaderWriter
-# (see __init__.py)
->>> strftimefmts = ['%Y-%m-%d %H:%M:%S', '%W WK %Y', '%Y-%m-%d', '%m Q %Y', '%Y-%m-%d',
-...                 '%Y-%m-%d', '%d %H:%M:%S', '%Y-%m-%d', '%B', '%B %Y', '%H:%M:%S.%f',
-...                 '%Y-%m-%d', '%A']
->>> data = SavReader(savFileName)
->>> with data:
-...     records = data.all()
-...     formats = formats.items()
-...     for n, record in enumerate(records):
-...         print("Record %d".center(79, "-") % n)
-...         for i, value in enumerate(record):
-...             print("%s --> %s --> %s" % (spssfmts[i], strftimefmts[i], value))
------------------------------------Record 0-----------------------------------
-DATETIME40 --> %Y-%m-%d %H:%M:%S --> 2010-08-11 00:00:00
-WKYR10 --> %W WK %Y --> 32 WK 2010
-DATE10 --> %Y-%m-%d --> 2010-08-11
-QYR10 --> %m Q %Y --> 3 Q 2010
-EDATE10 --> %Y-%m-%d --> 2010-08-11
-SDATE10 --> %Y-%m-%d --> 2010-08-11
-DTIME10 --> %d %H:%M:%S --> 11 00:00:00
-JDATE10 --> %Y-%m-%d --> 2010-08-11
-MONTH10 --> %B --> August
-MOYR10 --> %B %Y --> August 2010
-TIME10 --> %H:%M:%S.%f --> 00:00:00.000000
-ADATE10 --> %Y-%m-%d --> 2010-08-11
-WKDAY10 --> %A --> Wednesday
------------------------------------Record 1-----------------------------------
-DATETIME40 --> %Y-%m-%d %H:%M:%S --> 1910-01-12 00:00:00
-WKYR10 --> %W WK %Y --> 02 WK 1910
-DATE10 --> %Y-%m-%d --> 1910-01-12
-QYR10 --> %m Q %Y --> 1 Q 1910
-EDATE10 --> %Y-%m-%d --> 1910-01-12
-SDATE10 --> %Y-%m-%d --> 1910-01-12
-DTIME10 --> %d %H:%M:%S --> 12 00:00:00
-JDATE10 --> %Y-%m-%d --> 1910-01-12
-MONTH10 --> %B --> January
-MOYR10 --> %B %Y --> January 1910
-TIME10 --> %H:%M:%S.%f --> 00:00:00.000000
-ADATE10 --> %Y-%m-%d --> 1910-01-12
-WKDAY10 --> %A --> Wednesday
------------------------------------Record 2-----------------------------------
-DATETIME40 --> %Y-%m-%d %H:%M:%S --> None
-WKYR10 --> %W WK %Y --> None
-DATE10 --> %Y-%m-%d --> None
-QYR10 --> %m Q %Y --> None
-EDATE10 --> %Y-%m-%d --> None
-SDATE10 --> %Y-%m-%d --> None
-DTIME10 --> %d %H:%M:%S --> None
-JDATE10 --> %Y-%m-%d --> None
-MONTH10 --> %B --> None
-MOYR10 --> %B %Y --> None
-TIME10 --> %H:%M:%S.%f --> None
-ADATE10 --> %Y-%m-%d --> None
-WKDAY10 --> %A --> None
------------------------------------Record 3-----------------------------------
-DATETIME40 --> %Y-%m-%d %H:%M:%S --> None
-WKYR10 --> %W WK %Y --> None
-DATE10 --> %Y-%m-%d --> None
-QYR10 --> %m Q %Y --> None
-EDATE10 --> %Y-%m-%d --> None
-SDATE10 --> %Y-%m-%d --> None
-DTIME10 --> %d %H:%M:%S --> None
-JDATE10 --> %Y-%m-%d --> None
-MONTH10 --> %B --> None
-MOYR10 --> %B %Y --> None
-TIME10 --> %H:%M:%S.%f --> None
-ADATE10 --> %Y-%m-%d --> None
-WKDAY10 --> %A --> None
-
-
-## Test if recodeSysmisTo arg does what it is supposed to.
->>> data = SavReader(savFileName, recodeSysmisTo="999")
->>> with data:
-...     records = data.all()
-...     for n, record in enumerate(records):
-...         if n >= 2:
-...             print("Record %d".center(79, "-") % n)
-...             for i, value in enumerate(record):
-...                 print("%s --> %s --> %s" % (spssfmts[i], strftimefmts[i], value))
------------------------------------Record 2-----------------------------------
-DATETIME40 --> %Y-%m-%d %H:%M:%S --> 999
-WKYR10 --> %W WK %Y --> 999
-DATE10 --> %Y-%m-%d --> 999
-QYR10 --> %m Q %Y --> 999
-EDATE10 --> %Y-%m-%d --> 999
-SDATE10 --> %Y-%m-%d --> 999
-DTIME10 --> %d %H:%M:%S --> 999
-JDATE10 --> %Y-%m-%d --> 999
-MONTH10 --> %B --> 999
-MOYR10 --> %B %Y --> 999
-TIME10 --> %H:%M:%S.%f --> 999
-ADATE10 --> %Y-%m-%d --> 999
-WKDAY10 --> %A --> 999
------------------------------------Record 3-----------------------------------
-DATETIME40 --> %Y-%m-%d %H:%M:%S --> 999
-WKYR10 --> %W WK %Y --> 999
-DATE10 --> %Y-%m-%d --> 999
-QYR10 --> %m Q %Y --> 999
-EDATE10 --> %Y-%m-%d --> 999
-SDATE10 --> %Y-%m-%d --> 999
-DTIME10 --> %d %H:%M:%S --> 999
-JDATE10 --> %Y-%m-%d --> 999
-MONTH10 --> %B --> 999
-MOYR10 --> %B %Y --> 999
-TIME10 --> %H:%M:%S.%f --> 999
-ADATE10 --> %Y-%m-%d --> 999
-WKDAY10 --> %A --> 999
-
-
-# clean up
->>> os.remove(savFileName)

File savReaderWriter/doc_tests/test_SavReader_dates_elaborate.txt.old

-##############################################################################
-## Read a file containg all the supported date formats
-##############################################################################
-
->>> from __future__ import print_function
->>> import os
->>> from savReaderWriter import *
- 
-# these are the formats that are used internally by savReaderWriter
-# (see __init__.py)
->>> savFileName = b"../savReaderWriter/test_data/test_dates.sav"
->>> varNames = ['var_datetime', 'var_wkyr', 'var_date', 'var_qyr', 'var_edate',
-...             'var_sdate', 'var_dtime', 'var_jdate', 'var_month', 'var_moyr',
-...             'var_time', 'var_adate', 'var_wkday']
->>> varTypes = {v : 0 for v in varNames}
->>> spssfmts = ['DATETIME40', 'WKYR10', 'DATE10', 'QYR10', 'EDATE10',
-...             'SDATE10', 'DTIME10', 'JDATE10', 'MONTH10', 'MOYR10',
-...             'TIME10', 'ADATE10', 'WKDAY10']
->>> formats = dict(zip(varNames, spssfmts))
->>> strftimefmts = ['%Y-%m-%d %H:%M:%S', '%W WK %Y', '%Y-%m-%d', '%m Q %Y', '%Y-%m-%d',
-...                 '%Y-%m-%d', '%d %H:%M:%S', '%Y-%m-%d', '%B', '%B %Y', '%H:%M:%S.%f',
-...                 '%Y-%m-%d', '%A']
->>> data = SavReader(savFileName)
->>> with data:
-...     records = data.all()
-...     formats = formats.items()
-...     for n, record in enumerate(records):
-...         print("Record %d".center(79, "-") % n)
-...         for i, value in enumerate(record):
-...             value = value.decode("utf-8") if value is not None else value
-...             print("%s --> %s --> %s" % (spssfmts[i], strftimefmts[i], value))
------------------------------------Record 0-----------------------------------
-DATETIME40 --> %Y-%m-%d %H:%M:%S --> 2010-08-11 00:00:00
-WKYR10 --> %W WK %Y --> 32 WK 2010
-DATE10 --> %Y-%m-%d --> 2010-08-11
-QYR10 --> %m Q %Y --> 3 Q 2010
-EDATE10 --> %Y-%m-%d --> 2010-08-11
-SDATE10 --> %Y-%m-%d --> 2010-08-11
-DTIME10 --> %d %H:%M:%S --> 11 00:00:00
-JDATE10 --> %Y-%m-%d --> 2010-08-11
-MONTH10 --> %B --> August
-MOYR10 --> %B %Y --> August 2010
-TIME10 --> %H:%M:%S.%f --> 00:00:00.000000
-ADATE10 --> %Y-%m-%d --> 2010-08-11
-WKDAY10 --> %A --> Wednesday
------------------------------------Record 1-----------------------------------
-DATETIME40 --> %Y-%m-%d %H:%M:%S --> 1910-01-12 00:00:00
-WKYR10 --> %W WK %Y --> 02 WK 1910
-DATE10 --> %Y-%m-%d --> 1910-01-12
-QYR10 --> %m Q %Y --> 1 Q 1910
-EDATE10 --> %Y-%m-%d --> 1910-01-12
-SDATE10 --> %Y-%m-%d --> 1910-01-12
-DTIME10 --> %d %H:%M:%S --> 12 00:00:00
-JDATE10 --> %Y-%m-%d --> 1910-01-12
-MONTH10 --> %B --> January
-MOYR10 --> %B %Y --> January 1910
-TIME10 --> %H:%M:%S.%f --> 00:00:00.000000
-ADATE10 --> %Y-%m-%d --> 1910-01-12
-WKDAY10 --> %A --> Wednesday
------------------------------------Record 2-----------------------------------
-DATETIME40 --> %Y-%m-%d %H:%M:%S --> None
-WKYR10 --> %W WK %Y --> None
-DATE10 --> %Y-%m-%d --> None
-QYR10 --> %m Q %Y --> None
-EDATE10 --> %Y-%m-%d --> None
-SDATE10 --> %Y-%m-%d --> None
-DTIME10 --> %d %H:%M:%S --> None
-JDATE10 --> %Y-%m-%d --> None
-MONTH10 --> %B --> None
-MOYR10 --> %B %Y --> None
-TIME10 --> %H:%M:%S.%f --> None
-ADATE10 --> %Y-%m-%d --> None
-WKDAY10 --> %A --> None
------------------------------------Record 3-----------------------------------
-DATETIME40 --> %Y-%m-%d %H:%M:%S --> None
-WKYR10 --> %W WK %Y --> None
-DATE10 --> %Y-%m-%d --> None
-QYR10 --> %m Q %Y --> None
-EDATE10 --> %Y-%m-%d --> None
-SDATE10 --> %Y-%m-%d --> None
-DTIME10 --> %d %H:%M:%S --> None
-JDATE10 --> %Y-%m-%d --> None
-MONTH10 --> %B --> None
-MOYR10 --> %B %Y --> None
-TIME10 --> %H:%M:%S.%f --> None
-ADATE10 --> %Y-%m-%d --> None
-WKDAY10 --> %A --> None
-
-
-## Test if recodeSysmisTo arg does what it is supposed to.
->>> data = SavReader(savFileName, recodeSysmisTo="999")
->>> with data:
-...     records = data.all()
-...     #formats = formats.items()
-...     for n, record in enumerate(records):
-...         if n >= 2:
-...             print("Record %d".center(79, "-") % n)
-...             for i, value in enumerate(record):
-...                 print("%s --> %s --> %s" % (spssfmts[i], strftimefmts[i], value))
------------------------------------Record 2-----------------------------------
-DATETIME40 --> %Y-%m-%d %H:%M:%S --> 999
-WKYR10 --> %W WK %Y --> 999
-DATE10 --> %Y-%m-%d --> 999
-QYR10 --> %m Q %Y --> 999
-EDATE10 --> %Y-%m-%d --> 999
-SDATE10 --> %Y-%m-%d --> 999
-DTIME10 --> %d %H:%M:%S --> 999
-JDATE10 --> %Y-%m-%d --> 999
-MONTH10 --> %B --> 999
-MOYR10 --> %B %Y --> 999
-TIME10 --> %H:%M:%S.%f --> 999
-ADATE10 --> %Y-%m-%d --> 999
-WKDAY10 --> %A --> 999
------------------------------------Record 3-----------------------------------
-DATETIME40 --> %Y-%m-%d %H:%M:%S --> 999
-WKYR10 --> %W WK %Y --> 999
-DATE10 --> %Y-%m-%d --> 999
-QYR10 --> %m Q %Y --> 999
-EDATE10 --> %Y-%m-%d --> 999
-SDATE10 --> %Y-%m-%d --> 999
-DTIME10 --> %d %H:%M:%S --> 999
-JDATE10 --> %Y-%m-%d --> 999
-MONTH10 --> %B --> 999
-MOYR10 --> %B %Y --> 999
-TIME10 --> %H:%M:%S.%f --> 999
-ADATE10 --> %Y-%m-%d --> 999
-WKDAY10 --> %A --> 999

File savReaderWriter/doc_tests/test_SavReader_file_info.txt

-##############################################################################
-## Read a file and get some basic file info
-##############################################################################
-
->>> from savReaderWriter import *
-
-## ... Get some basic file info
->>> savFileName = "../savReaderWriter/test_data/Employee data.sav"
->>> reader = None
->>> try:  # doctest: +ELLIPSIS
-...     reader = SavReader(savFileName)      
-...     numVars, nCases, varNames, varTypes, formats, \
-...          varLabels, valueLabels = reader.getSavFileInfo()
-...     info = reader.getSavFileInfo()
-... finally:
-...     if reader is not None: 
-...         reader.close()
-...
->>> desired = \
-... (10,
-...  474,
-...  [b'id',
-...   b'gender',
-...   b'bdate',
-...   b'educ',
-...   b'jobcat',
-...   b'salary',
-...   b'salbegin',
-...   b'jobtime',
-...   b'prevexp',
-...   b'minority'],
-...  {b'bdate': 0,
-...   b'educ': 0,
-...   b'gender': 1,
-...   b'id': 0,
-...   b'jobcat': 0,
-...   b'jobtime': 0,
-...   b'minority': 0,
-...   b'prevexp': 0,
-...   b'salary': 0,
-...   b'salbegin': 0},
-...  {b'bdate': b'ADATE10',
-...   b'educ': b'F2',
-...   b'gender': b'A1',
-...   b'id': b'F4',
-...   b'jobcat': b'F1',
-...   b'jobtime': b'F2',
-...   b'minority': b'F1',
-...   b'prevexp': b'F6',
-...   b'salary': b'DOLLAR8',
-...   b'salbegin': b'DOLLAR8'},
-...  {b'bdate': b'Date of Birth',
-...   b'educ': b'Educational Level (years)',
-...   b'gender': b'Gender',
-...   b'id': b'Employee Code',
-...   b'jobcat': b'Employment Category',
-...   b'jobtime': b'Months since Hire',
-...   b'minority': b'Minority Classification',
-...   b'prevexp': b'Previous Experience (months)',
-...   b'salary': b'Current Salary',
-...   b'salbegin': b'Beginning Salary'},
-...  {b'educ': {0.0: b'0 (Missing)',
-...            8.0: b'8',
-...            12.0: b'12',
-...            14.0: b'14',
-...            15.0: b'15',
-...            16.0: b'16',
-...            17.0: b'17',
-...            18.0: b'18',
-...            19.0: b'19',
-...            20.0: b'20',
-...            21.0: b'21'},
-...   b'gender': {b'f': b'Female', b'm': b'Male'},
-...   b'jobcat': {0.0: b'0 (Missing)',
-...              1.0: b'Clerical',
-...              2.0: b'Custodial',
-...              3.0: b'Manager'},
-...   b'jobtime': {0.0: b'missing'},
-...   b'minority': {0.0: b'No', 1.0: b'Yes', 9.0: b'9 (Missing)'},
-...   b'prevexp': {0.0: b'missing'},
-...   b'salary': {0.0: b'missing'},
-...   b'salbegin': {0.0: b'missing'}})
->>> desired == info
-True

File savReaderWriter/doc_tests/test_SavWriter_mode_ab.txt

-##############################################################################
-## Append some records to an existing file, using mode="ab"
-##############################################################################
-
->>> from __future__ import print_function
->>> import shutil
->>> import os
->>> from savReaderWriter import *
-
-## Append some records to an existing file
-## First make a copy to work with (append records to)
-## Also retrieve varNames and varTypes as these are mandatory args
->>> savFileName = "../savReaderWriter/test_data/Employee data.sav"
->>> crap = shutil.copy(savFileName, "Employee data copy.sav")
->>> reader = None
->>> try:  # doctest: +ELLIPSIS
-...     reader = SavReader(savFileName, rawMode=True)
-...     NROWS_ORIGINAL = len(reader)
-...     varNames, varTypes = reader.getSavFileInfo()[2:4]
-... finally:
-...     # Don't forget this! You won't be able to change interface mode (ioUtf8)
-...     if reader is not None:
-...         reader.close()
-...
-
-## Append 100 records to the file
->>> NROWS_EXTRA = 100
->>> savFileName = "Employee data copy.sav"
->>> with SavWriter(savFileName, varNames, varTypes, mode="ab") as writer:
-...     line = [1.0, 'm', 11654150400.0, 15.0, 3.0, 57000.0, 27000.0, 98.0, 144.0, 0.0]
-...     for i in range(NROWS_EXTRA):
-...         writer.writerow(line)
-
-## Demonstrate that the number of records has increased by 100.
->>> reader = None
->>> try: # doctest: +ELLIPSIS
-...     reader = SavReader(savFileName)
-...     print(len(reader) == NROWS_ORIGINAL + NROWS_EXTRA)
-... finally:
-...     if reader is not None:
-...         reader.close()
-...
-True
-
-# clean up
->>> try:
-...     os.remove(os.path.abspath(savFileName))
-... except:
-...     pass 
-

File savReaderWriter/doc_tests/test_SavWriter_mode_cp.txt

-##############################################################################
-## Use a nested context manager and mode="cp"
-##############################################################################
-
->>> from __future__ import print_function
->>> import os
->>> from savReaderWriter import *
-
-###############
-## Copy header info from one file to another (Method #1)
->>> savFileName = "../savReaderWriter/test_data/Employee data.sav"
->>> with SavHeaderReader(savFileName) as spssDict:
-...     wholeDict = spssDict.dataDictionary()  # doctest: +ELLIPSIS
-...
->>> with SavReader(savFileName) as reader:
-...     with SavWriter("test_wholeDict.sav", **wholeDict) as writer:
-...         for line in reader:
-...             writer.writerow(line)
-
-# clean up
->>> try:
-...     os.remove(os.path.abspath("test_wholeDict.sav"))
-... except:
-...     pass
-
-###############
-## Copy header info from one file to another (Method #2)
-## Uses <refSavFileName> as a donor file to initialize the header
-## This will also copy DATE/TREND info, which is not copied using Method #1
->>> savFileName = "../savReaderWriter/test_data/Employee data.sav"
->>> with SavReader(savFileName, rawMode=True) as reader:
-...     varNames, varTypes = reader.getSavFileInfo()[2:4]
-...     with SavWriter("Employee data_out.sav", varNames, varTypes,
-...                    refSavFileName=savFileName, mode="cp") as writer:
-...         for line in reader:
-...             writer.writerow(line)
-
-# read the data back in to see if it looks the same
->>> with SavReader("Employee data_out.sav", returnHeader=True) as reader:  # doctest: +ELLIPSIS
-...     header = reader.next()
-...     print(header)
-...     for line in reader:
-...         print(line)
-['id', 'gender', 'bdate', 'educ', 'jobcat', 'salary', 'salbegin', 'jobtime', 'prevexp', 'minority']
-[1.0, 'm', '1952-02-03', 15.0, 3.0, 57000.0, 27000.0, 98.0, 144.0, 0.0]
-[2.0, 'm', '1958-05-23', 16.0, 1.0, 40200.0, 18750.0, 98.0, 36.0, 0.0]
-[3.0, 'f', '1929-07-26', 12.0, 1.0, 21450.0, 12000.0, 98.0, 381.0, 0.0]
-...
-[462.0, 'f', '1963-10-18', 16.0, 3.0, 34410.0, 19500.0, 65.0, 79.0, 0.0]
-[463.0, 'f', '1934-10-15', 15.0, 1.0, 20700.0, 14250.0, 65.0, 241.0, 0.0]
-[464.0, 'm', '1962-03-20', 19.0, 3.0, 47550.0, 33000.0, 64.0, 27.0, 0.0]
-[465.0, 'm', '1962-07-20', 12.0, 1.0, 33900.0, 16500.0, 64.0, 106.0, 0.0]
-[466.0, 'f', '1948-06-15', 12.0, 1.0, 23400.0, 13500.0, 64.0, 198.0, 0.0]
-[467.0, 'f', '1967-08-18', 16.0, 1.0, 32850.0, 19500.0, 64.0, 20.0, 0.0]
-[468.0, 'f', '1965-11-28', 16.0, 3.0, 55750.0, 19980.0, 64.0, 36.0, 0.0]
-[469.0, 'f', '1964-06-01', 15.0, 1.0, 25200.0, 13950.0, 64.0, 57.0, 0.0]
-[470.0, 'm', '1964-01-22', 12.0, 1.0, 26250.0, 15750.0, 64.0, 69.0, 1.0]
-[471.0, 'm', '1966-08-03', 15.0, 1.0, 26400.0, 15750.0, 64.0, 32.0, 1.0]
-[472.0, 'm', '1966-02-21', 15.0, 1.0, 39150.0, 15750.0, 63.0, 46.0, 0.0]
-[473.0, 'f', '1937-11-25', 12.0, 1.0, 21450.0, 12750.0, 63.0, 139.0, 0.0]
-[474.0, 'f', '1968-11-05', 12.0, 1.0, 29400.0, 14250.0, 63.0, 9.0, 0.0]
-
-# read the meta data back in to see if it looks the same
->>> with SavHeaderReader("Employee data_out.sav") as header:  # doctest: +ELLIPSIS
-...     print(str(header))
-...
-#ALIGNMENTS
-salary -- right
-jobcat -- right
-bdate -- right
-minority -- right
-prevexp -- right
-gender -- left
-salbegin -- right
-jobtime -- right
-educ -- right
-id -- right
-#CASEWEIGHTVAR
-#COLUMNWIDTHS
-salary -- 8
-jobcat -- 8
-bdate -- 13
-minority -- 8
-prevexp -- 8
-gender -- 1
-salbegin -- 8
-jobtime -- 8
-educ -- 8
-id -- 8
-#FILEATTRIBUTES
-#FILELABEL
-05.00.00
-#FORMATS
-salary -- DOLLAR8
-jobcat -- F1
-bdate -- ADATE10
-minority -- F1
-prevexp -- F6
-gender -- A1
-salbegin -- DOLLAR8
-jobtime -- F2
-educ -- F2
-id -- F4
-#MEASURELEVELS
-salary -- ratio
-jobcat -- ordinal
-bdate -- ratio
-minority -- ordinal
-prevexp -- ratio
-gender -- nominal
-salbegin -- ratio
-jobtime -- ratio
-educ -- ordinal
-id -- ratio
-#MISSINGVALUES
-salary: values -- 0.0
-jobcat: values -- 0.0
-minority: values -- 9.0
-salbegin: values -- 0.0
-jobtime: values -- 0.0
-educ: values -- 0.0
-#MULTRESPDEFS
-#VALUELABELS
-salary: 0.0 -- missing
-jobcat: 0.0 -- 0 (Missing)
-jobcat: 1.0 -- Clerical
-jobcat: 2.0 -- Custodial
-jobcat: 3.0 -- Manager
-salbegin: 0.0 -- missing
-minority: 0.0 -- No
-minority: 1.0 -- Yes
-minority: 9.0 -- 9 (Missing)
-prevexp: 0.0 -- missing
-gender: f -- Female
-gender: m -- Male
-jobtime: 0.0 -- missing
-educ: 0.0 -- 0 (Missing)
-educ: 8.0 -- 8
-educ: 12.0 -- 12
-educ: 14.0 -- 14
-educ: 15.0 -- 15
-educ: 16.0 -- 16
-educ: 17.0 -- 17
-educ: 18.0 -- 18
-educ: 19.0 -- 19
-educ: 20.0 -- 20
-educ: 21.0 -- 21
-#VARATTRIBUTES
-#VARLABELS
-salary -- Current Salary
-jobcat -- Employment Category
-bdate -- Date of Birth
-minority -- Minority Classification
-prevexp -- Previous Experience (months)
-gender -- Gender
-salbegin -- Beginning Salary
-jobtime -- Months since Hire
-educ -- Educational Level (years)
-id -- Employee Code
-#VARNAMES
-id
-gender
-bdate
-educ
-jobcat
-salary
-salbegin
-jobtime
-prevexp
-minority
-#VARROLES
-salary -- input
-jobcat -- input
-bdate -- input
-minority -- input
-prevexp -- input
-gender -- input
-salbegin -- input
-jobtime -- input
-educ -- input
-id -- input
-#VARSETS
-SALARY -- salbegin, salary
-DEMOGR -- gender, minority, educ
-#VARTYPES
-salary -- 0
-jobcat -- 0
-bdate -- 0
-minority -- 0
-prevexp -- 0
-gender -- 1
-salbegin -- 0
-jobtime -- 0
-educ -- 0
-id -- 0
-
-# clean up
->>> try:
-...     os.remove(os.path.abspath("Employee data_out.sav"))
-... except:
-...     pass 
-
-

File savReaderWriter/doc_tests/test_SavWriter_multRespDefs.txt

-##############################################################################
-## Write multiple response definitions
-##############################################################################
-
->>> import os
->>> import tempfile
->>> from savReaderWriter import *
-
-# preparare some data
->>> records = [['Test1', 1, 1, 'Yes', 'No'], ['Test2', 2, 1, 'No', 'Yes']]
->>> varNames = ['v1', 'v2', 'v3', 'yn', 'yeah']
->>> varTypes = {'v1': 5, 'v2': 0, 'v3': 0, 'yn': 3, 'yeah': 3}
->>> savFileName = os.path.join(tempfile.gettempdir(), 'test.sav')
->>> def checkMultRespDefs(savFileName):
-...     with SavHeaderReader(savFileName) as spssDict:
-...         wholeDict = spssDict.dataDictionary()
-...         return wholeDict['multRespDefs']
-
-###########
-# Categorical sets
-###########
-# Was already ok
->>> categorical = {'setType': 'C', 'label': 'labelC',  'varNames': ['v2', 'v3']}
->>> multRespDefs = dict(categorical=categorical)
->>> kwargs = dict(savFileName=savFileName, varNames=varNames,
-...               varTypes=varTypes, multRespDefs=multRespDefs)
->>> with SavWriter(**kwargs) as writer:
-...     writer.writerows(records)
->>> desired = {'categorical': {'label': 'labelC', 'setType': 'C', 'varNames': ['v2', 'v3']}}
->>> checkMultRespDefs(savFileName) == desired
-True
-
-
-###########
-# Dichotomous sets
-###########
-# 2013-06-13 FIXED
-# previously "Assertion `length != 0' failed. Aborted (core dumped)"
->>> dichotomous1 = {'setType': 'D', 'label': 'labelD',
-...                 'varNames': ['yn', 'yeah'], 'countedValue': 'Yes'}
->>> multRespDefs = dict(dichotomous1=dichotomous1)
->>> kwargs = dict(savFileName=savFileName, varNames=varNames,
-...               varTypes=varTypes, multRespDefs=multRespDefs)
->>> with SavWriter(**kwargs) as writer:
-...     writer.writerows(records)
->>> desired = {'dichotomous1': {'countedValue': 'Yes',
-...            'label': 'labelD',
-...            'setType': 'D',
-...            'varNames': ['yn', 'yeah']}}
->>> checkMultRespDefs(savFileName) == desired
-True
-
-
->>> dichotomous2 = {"setType": "D", "label": "", "varNames":
-...                 ["v1", "v2", "v3"], "countedValue": "No"}
->>> multRespDefs = dict(dichotomous2=dichotomous2)
->>> kwargs = dict(savFileName=savFileName, varNames=varNames,
-...               varTypes=varTypes, multRespDefs=multRespDefs)
->>> with SavWriter(**kwargs) as writer:
-...     writer.writerows(records)
->>> desired = {'dichotomous2': {'countedValue': 'No',
-...            'label': '',
-...            'setType': 'D',
-...            'varNames': ['v1', 'v2', 'v3']}}
->>> checkMultRespDefs(savFileName) == desired
-True
-
-
-### unicode mode (ioUtf8=True)
->>> uthai = u'\u0e2a\u0e27\u0e31\u0e2a\u0e14\u0e35'
->>> dichotomous3 = {"setType": "D", "label": uthai,
-...                 "varNames": ["v1", "v2"], "countedValue": uthai}
->>> multRespDefs = dict(dichotomous3=dichotomous3)
->>> kwargs = dict(savFileName=savFileName,
-...               varNames=varNames,
-...               varTypes=varTypes,
-...               multRespDefs=multRespDefs,
-...               ioUtf8=True)
->>> with SavWriter(**kwargs) as writer:
-...     writer.writerows(records)
->>> thai = ('\xe0\xb8\xaa\xe0\xb8\xa7\xe0\xb8\xb1' + 
-...         '\xe0\xb8\xaa\xe0\xb8\x94\xe0\xb8\xb5')
->>> desired = {'dichotomous3': {'countedValue': thai,
-...            'label': thai,
-...            'setType': 'D',
-...            'varNames': ['v1', 'v2']}}
->>> checkMultRespDefs(savFileName) == desired
-True
->>> uthai == thai.decode("utf-8")
-True
-
-# clean up
->>> os.remove(savFileName)

File savReaderWriter/doc_tests/test_SavWriter_typical.txt

-##############################################################################
-## Write a file, typical use
-##############################################################################
-
->>> from __future__ import print_function
->>> import os
->>> import tempfile
->>> from savReaderWriter import *
-
-
-## ----- Typical use
->>> records = [['Test1', 1, 1, '2010-08-11'], ['Test2', 2, 1, '1910-01-12']]
->>> varNames = ['var1', 'v2', 'v3', 'bdate']
->>> varTypes = {'var1': 6, 'v2': 0, 'v3': 0, 'bdate': 10}
->>> savFileName = os.path.join(tempfile.gettempdir(), "test.sav")
->>> with SavWriter(savFileName, varNames, varTypes) as sav:
-...     for record in records:
-...         sav.writerow(record)
-...     print("Done! %s" % os.path.basename(sav.savFileName))
-Done! test.sav
-
-# read it back in
->>> reader = None
->>> try:
-...     reader = SavReader(savFileName)  # doctest: +ELLIPSIS
-...     records_out = [line for line in iter(reader)]
-...     print(records_out == records)
-... finally:
-...     if reader is not None:
-...         reader.close()
-True
-
-# clean up
->>> try:
-...     os.remove(savFileName)
-... except:
-...    pass
-
-

File savReaderWriter/doc_tests/test_SavWriter_utf8_mode.txt

-##############################################################################
-## Write a file in utf8 mode aka unicode mode (ioUtf8=True)
-##############################################################################
-
->>> import os
->>> import tempfile
->>> from savReaderWriter import *
-
-## ... check if non-ascii encodings work well
-## ... notice the use of 'ioUtf8'
-## ... source: http://www.omniglot.com/language/phrases/hello.htm
->>> greetings = [
-...     ['Arabic', u'\u0627\u0644\u0633\u0644\u0627\u0645\u0020\u0639\u0644\u064a\u0643\u0645'],
-...     ['Assamese', u'\u09a8\u09ae\u09b8\u09cd\u0995\u09be\u09f0'],
-...     ['Bengali', u'\u0986\u09b8\u09b8\u09be\u09b2\u09be\u09ae\u09c1\u0986\u09b2\u09be\u0987\u0995\u09c1\u09ae'],
-...     ['English', u'Greetings and salutations'],
-...     ['Georgian', u'\u10d2\u10d0\u10db\u10d0\u10e0\u10ef\u10dd\u10d1\u10d0'],
-...     ['Kazakh', u'\u0421\u04d9\u043b\u0435\u043c\u0435\u0442\u0441\u0456\u0437 \u0431\u0435'],
-...     ['Russian', u'\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435'],
-...     ['Spanish', u'\xa1Hola!'],
-...     ['Swiss German', u'Gr\xfcezi'],
-...     ['Thai', u'\u0e2a\u0e27\u0e31\u0e2a\u0e14\u0e35'],
-...     ['Walloon', u'Bondjo\xfb'],
-...     ]
->>> savFileName = os.path.join(tempfile.gettempdir(), "greetings.sav")
->>> varNames = [u'Bondjo\xfb', 'greeting']
->>> varTypes = {u'Bondjo\xfb': 20, 'greeting': 50}
->>> valueLabels = {u'Bondjo\xfb': {'Thai': u'\u0e2a\u0e27\u0e31\u0e2a\u0e14\u0e35'}}
->>> missingValues = {u'Bondjo\xfb': {'values': u'\xa1Hola!'}}
->>> varLabels = {'greeting': u'\u0627\u0644\u0633\u0644\u0627\u0645\u0020\u0639\u0644\u064a\u0643\u0645'}
->>> with SavWriter(savFileName, varNames, varTypes, valueLabels, varLabels,
-...                missingValues=missingValues, ioUtf8=True) as sav:
-...     sav.writerows(greetings)
-
-
-# read the file back in ---> error/nuisance with null bytes!!
-# BUG: the null bytes are supposed to be stripped or replaced with space!
->>> records_expected = \
-... [[u'Arabic',
-...   u'\u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u064a\u0643\u0645'],
-...  [u'Assamese', u'\u09a8\u09ae\u09b8\u09cd\u0995\u09be\u09f0'],
-...  [u'Bengali',
-...   u'\u0986\u09b8\u09b8\u09be\u09b2\u09be\u09ae\u09c1\u0986\u09b2\u09be\u0987\u0995\u09c1\u09ae'],
-...  [u'English', u'Greetings and salutations'],
-...  [u'Georgian', u'\u10d2\u10d0\u10db\u10d0\u10e0\u10ef\u10dd\u10d1\u10d0'],
-...  [u'Kazakh',
-...   u'\u0421\u04d9\u043b\u0435\u043c\u0435\u0442\u0441\u0456\u0437 \u0431\u0435'],
-...  [u'Russian',
-...   u'\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435'],
-...  [u'Spanish', u'\xa1Hola!'],
-...  [u'Swiss German', u'Gr\xfcezi'],
-...  [u'Thai', u'\u0e2a\u0e27\u0e31\u0e2a\u0e14\u0e35'],
-...  [u'Walloon', u'Bondjo\xfb']]
->>> with SavReader(savFileName, ioUtf8=True)as sav:   # doctest: +ELLIPSIS
-...     records_got = [[line[0].rstrip(), line[1].rstrip("\x00")] for line in sav]
-...     records_expected == records_got
-True
-
-# clean up
->>> try:
-...     os.remove(savFileName)
-... except:
-...     pass   
-

File savReaderWriter/doc_tests/test_SavWriter_writerow_date.txt

-##############################################################################
-## Write a file, incl. SPSS date values
-##############################################################################
-
->>> from __future__ import print_function
->>> import os
->>> import tempfile
->>> from savReaderWriter import *
-
-## ----- Write one row
-# var1 is a 5-char string var, the others are numerical:
-# formats, varLabels, valueLabels, missingValues etc. may also be None (default).
-# This also shows how date fields can be converted into spss dates.
-# Spss dates are *stored* as the number of seconds since Oct 14, 1582, but
-# *displayed* as <format>. In this case they are displayed as EDATE
-# (European date, cf. ADATE = American date), ie. as dd.mm.yyyy
-
->>> records = [['Test1', 1, 1, '2010-08-11'], ['Test2', 2, 1, '1910-01-12']]
->>> varNames = ['var1', 'v2', 'v3', 'bdate']
->>> varTypes = {'var1': 41, 'v2': 0, 'v3': 0, 'bdate': 0}
->>> formats = {'var1': 'A41', 'v2': 'F3.1', 'v3': 'F5.1', 'bdate': 'EDATE40'}
->>> missingValues = {'var1': {'values': ['Test1', 'Test2']},
-...                  'v2': {'values': 1}}
->>> varLabels = {'var1': 'This is variable 1',
-...              'v2': 'This is v2!',
-...              'bdate': 'dob'}
->>> valueLabels = {'var1': {'Test1': 'Test1 value label',
-...                         'Test2': 'Test2 value label'},
-...                'v2': {1: 'yes', 2: 'no'}}
->>> savFileName = os.path.join(tempfile.gettempdir(), "test.sav")
->>> with SavWriter(savFileName, varNames, varTypes,
-...                valueLabels, varLabels, formats) as sav:
-...     pos = varNames.index("bdate")
-...     for record in records:
-...         record[pos] = sav.spssDateTime(record[pos], "%Y-%m-%d")
-...         print(record)
-...         sav.writerow(record)
-...     print("Done! %s" % os.path.basename(sav.savFileName))
-['Test1', 1, 1, 13500864000.0]
-['Test2', 2, 1, 10326873600.0]
-Done! test.sav
-
-# read it back in in rawMode (dates not converted to ISO-dates)
->>> reader = None
->>> try:
-...     reader = SavReader(savFileName, rawMode=True)  # doctest: +ELLIPSIS
-...     records_out = [line for line in iter(reader)]
-... finally:
-...     if reader is not None:
-...         reader.close()
-...
->>> print(records_out == records)
-True
-
-# clean up
->>> try:
-...     os.remove(os.path.abspath(savFileName))
-... except:
-...     pass 
-
-

File savReaderWriter/doc_tests/test_SavWriter_writerows_elaborate.txt

-##############################################################################
-## Write a file (elaborate example)
-##############################################################################
-
->>> from __future__ import print_function
->>> import os
->>> import tempfile
->>> from savReaderWriter import *
-
-## ----- Write many rows
->>> savFileName = os.path.join(tempfile.gettempdir(), "employee data_OUT.sav")
->>> varNames = ['id', 'gender', 'bdate', 'educ', 'jobcat', 'salary', 'salbegin',
-...             'jobtime', 'prevexp', 'minority']
->>> varLabels = {'gender': 'guys/gals'}
->>> varTypes = {'salary': 0, 'jobcat': 0, 'bdate': 0, 'minority': 0,
-...             'prevexp': 0, 'gender': 1, 'salbegin': 0, 'jobtime': 0,
-...             'educ': 0, 'id': 0}
->>> formats = {'salary': 'DOLLAR8', 'jobcat': 'F3', 'bdate': 'ADATE40',
-...            'minority': 'F3', 'prevexp': 'F3', 'gender': 'A1', 'salbegin':
-...            'DOLLAR8', 'jobtime': 'F8', 'educ': 'F3', 'id': 'N9'}
->>> varSets = {'SALARY': ['salbegin', 'salary'],
-...            'DEMOGR': ['gender', 'minority', 'educ']}
->>> varAttributes = {'salary': {'DemographicVars': '1'},
-...                  'jobcat': {'DemographicVars': '1'},
-...                  'gender': {'Binary': 'Yes'},
-...                  'educ': {'DemographicVars': '1'}}
->>> fileAttributes = {'TheDate[2]': '10/21/2005', 'RevisionDate[2]': '10/21/2005',
-...                   'RevisionDate[1]': '10/29/2004'}
->>> missingValues = {'educ': {'values': [1, 2, 3]}, 'gender': {'values': 'x'}}
->>> records = [[1.0, 'm       ', 11654150400.0, 15.0, 3.0,
-...             57000.0, 27000.0, 98.0, 144.0, 0.0],
-...            [2.0, 'm       ', 11852956800.0, 16.0, 1.0,
-...             40200.0, 18750.0, 98.0, 36.0, 0.0]]
->>> with SavWriter(savFileName, varNames, varTypes,
-...                varLabels=varLabels, varSets=varSets,
-...                missingValues=missingValues, varAttributes=varAttributes,
-...                fileAttributes=fileAttributes) as sav:
-...     sav.writerows(records)
-...     print("Done! %s" % os.path.basename(sav.savFileName))
-Done! employee data_OUT.sav
-
-# read it back in 
->>> reader = None
->>> try:
-...     reader = SavReader(savFileName, rawMode=True)  # doctest: +ELLIPSIS
-...     records_out = [line for line in iter(reader)]
-... finally:
-...     if reader is not None:
-...         reader.close()
->>> print(records_out == records)  # doctest: +NORMALIZE_WHITESPACE
-True
-
-# check if the header info is okay
->>> with SavHeaderReader(savFileName) as h:
-...     print(str(h))  # doctest: +ELLIPSIS
-...
-File 'employee data_OUT.sav' built using savReaderWriter version ... (...:...:...)
-#ALIGNMENTS
-salary -- left
-jobcat -- left
-bdate -- left
-minority -- left
-prevexp -- left
-gender -- left
-salbegin -- left
-jobtime -- left
-educ -- left
-id -- left
-#CASEWEIGHTVAR
-#COLUMNWIDTHS
-salary -- 8
-jobcat -- 8
-bdate -- 8
-minority -- 8
-prevexp -- 8
-gender -- 10
-salbegin -- 8
-jobtime -- 8
-educ -- 8
-id -- 8
-#FILEATTRIBUTES
-TheDate[2] -- 5
-RevisionDate[2] -- 5
-RevisionDate[1] -- 4
-#FILELABEL
-File created by user '...' at ...
-#FORMATS
-salary -- F8.2
-jobcat -- F8.2
-bdate -- F8.2
-minority -- F8.2
-prevexp -- F8.2
-gender -- A1
-salbegin -- F8.2
-jobtime -- F8.2
-educ -- F8.2
-id -- F8.2
-#MEASURELEVELS
-salary -- unknown
-jobcat -- unknown
-bdate -- unknown
-minority -- unknown
-prevexp -- unknown
-gender -- unknown
-salbegin -- unknown
-jobtime -- unknown
-educ -- unknown
-id -- unknown
-#MISSINGVALUES
-gender: values -- x
-educ: values -- 1.0, 2.0, 3.0
-#MULTRESPDEFS
-#VALUELABELS
-#VARATTRIBUTES
-salary: DemographicVars -- 1
-gender: Binary -- Yes
-educ: DemographicVars -- 1
-jobcat: DemographicVars -- 1
-#VARLABELS
-gender -- guys/gals
-#VARNAMES
-id
-gender
-bdate
-educ
-jobcat
-salary
-salbegin
-jobtime
-prevexp
-minority
-#VARROLES
-salary -- input
-jobcat -- input
-bdate -- input
-minority -- input
-prevexp -- input
-gender -- input
-salbegin -- input
-jobtime -- input
-educ -- input
-id -- input
-#VARSETS
-SALARY -- salbegin, salary
-DEMOGR -- gender, minority, educ
-#VARTYPES
-salary -- 0
-jobcat -- 0
-bdate -- 0
-minority -- 0
-prevexp -- 0
-gender -- 1
-salbegin -- 0
-jobtime -- 0
-educ -- 0
-id -- 0
-
-# clean up
->>> try:
-...     os.remove(savFileName)
-... except:
-...     pass
-
-

File savReaderWriter/doc_tests/test_SavWriter_writerows_zsav.txt

-##############################################################################
-## Write a file, in zsav compressed format
-##############################################################################
-
->>> from __future__ import print_function
->>> import os
->>> import tempfile
->>> import sys
->>> from savReaderWriter import *
-
-## ----- Write many rows
-# .zsav = zlib compressed (--> >= v21 libs)
->>> savFileName = os.path.join(tempfile.gettempdir(), "test.zsav")
->>> records = [['Test1', 1, 1, '2010-08-11'], ['Test2', 2, 1, '1910-01-12']]
->>> varNames = ['var1', 'var2', 'var3', 'bdate']
->>> varTypes = {'var1': 50, 'var2': 0, 'var3': 0, 'bdate': 10}
->>> with SavWriter(savFileName, varNames, varTypes) as sav:
-...     sav.writerows(records)
-...     print("Done! %s" % os.path.basename(sav.savFileName))
-Done! test.zsav
-
-# read it back in
->>> reader = None
->>> try: 
-...     reader = SavReader(savFileName)  # doctest: +ELLIPSIS
-...     records_out = [line for line in iter(reader)]
-... finally:
-...     if reader is not None:
-...         reader.close()
->>> print(records_out == records)
-True
-
-# clean up
->>> try:
-...     os.remove(savFileName)
-... except:
-...     pass
 [tox]
 envlist = py27,py33,pypy
-indexserver = 
-    default = https://pypi.python.org/pypi
+skipsdist = True
+deps = setuptools \
+       nose \
+       gocept.testing 
 [testenv]
-commands = nosetests
-deps = setuptools
+commands = nosetests \
+           [] 
+