Commits

AJ R committed b6daa66

All tests (except one skipped) of test_SavHeaderReader_dataDict_namedtuple.py run in Python 2 and 3

  • Participants
  • Parent commits 24e2bf3

Comments (0)

Files changed (3)

savReaderWriter/__init__.py

 
 
 allFormats = {
-    1: ("SPSS_FMT_A", "Alphanumeric"),
-    2: ("SPSS_FMT_AHEX", "Alphanumeric hexadecimal"),
-    3: ("SPSS_FMT_COMMA", "F Format with commas"),
-    4: ("SPSS_FMT_DOLLAR", "Commas and floating dollar sign"),
-    5: ("SPSS_FMT_F", "Default Numeric Format"),
-    6: ("SPSS_FMT_IB", "Integer binary"),
-    7: ("SPSS_FMT_PIBHEX", "Positive integer binary - hex"),
-    8: ("SPSS_FMT_P", "Packed decimal"),
-    9: ("SPSS_FMT_PIB", "Positive integer binary unsigned"),
-    10: ("SPSS_FMT_PK", "Positive integer binary unsigned"),
-    11: ("SPSS_FMT_RB", "Floating point binary"),
-    12: ("SPSS_FMT_RBHEX", "Floating point binary hex"),
-    15: ("SPSS_FMT_Z", "Zoned decimal"),
-    16: ("SPSS_FMT_N", "N Format- unsigned with leading 0s"),
-    17: ("SPSS_FMT_E", "E Format- with explicit power of 10"),
-    20: ("SPSS_FMT_DATE", "Date format dd-mmm-yyyy"),
-    21: ("SPSS_FMT_TIME", "Time format hh:mm:ss.s"),
-    22: ("SPSS_FMT_DATETIME", "Date and Time"),
-    23: ("SPSS_FMT_ADATE", "Date format dd-mmm-yyyy"),
-    24: ("SPSS_FMT_JDATE", "Julian date - yyyyddd"),
-    25: ("SPSS_FMT_DTIME", "Date-time dd hh:mm:ss.s"),
-    26: ("SPSS_FMT_WKDAY", "Day of the week"),
-    27: ("SPSS_FMT_MONTH", "Month"),
-    28: ("SPSS_FMT_MOYR", "mmm yyyy"),
-    29: ("SPSS_FMT_QYR", "q Q yyyy"),
-    30: ("SPSS_FMT_WKYR", "ww WK yyyy"),
-    31: ("SPSS_FMT_PCT", "Percent - F followed by %"),
-    32: ("SPSS_FMT_DOT", "Like COMMA, switching dot for comma"),
-    33: ("SPSS_FMT_CCA", "User Programmable currency format"),
-    34: ("SPSS_FMT_CCB", "User Programmable currency format"),
-    35: ("SPSS_FMT_CCC", "User Programmable currency format"),
-    36: ("SPSS_FMT_CCD", "User Programmable currency format"),
-    37: ("SPSS_FMT_CCE", "User Programmable currency format"),
-    38: ("SPSS_FMT_EDATE", "Date in dd/mm/yyyy style"),
-    39: ("SPSS_FMT_SDATE", "Date in yyyy/mm/dd style")}
+    1: (b"SPSS_FMT_A", b"Alphanumeric"),
+    2: (b"SPSS_FMT_AHEX", b"Alphanumeric hexadecimal"),
+    3: (b"SPSS_FMT_COMMA", b"F Format with commas"),
+    4: (b"SPSS_FMT_DOLLAR", b"Commas and floating dollar sign"),
+    5: (b"SPSS_FMT_F", b"Default Numeric Format"),
+    6: (b"SPSS_FMT_IB", b"Integer binary"),
+    7: (b"SPSS_FMT_PIBHEX", b"Positive integer binary - hex"),
+    8: (b"SPSS_FMT_P", b"Packed decimal"),
+    9: (b"SPSS_FMT_PIB", b"Positive integer binary unsigned"),
+    10: (b"SPSS_FMT_PK", b"Positive integer binary unsigned"),
+    11: (b"SPSS_FMT_RB", b"Floating point binary"),
+    12: (b"SPSS_FMT_RBHEX", b"Floating point binary hex"),
+    15: (b"SPSS_FMT_Z", b"Zoned decimal"),
+    16: (b"SPSS_FMT_N", b"N Format- unsigned with leading 0s"),
+    17: (b"SPSS_FMT_E", b"E Format- with explicit power of 10"),
+    20: (b"SPSS_FMT_DATE", b"Date format dd-mmm-yyyy"),
+    21: (b"SPSS_FMT_TIME", b"Time format hh:mm:ss.s"),
+    22: (b"SPSS_FMT_DATETIME", b"Date and Time"),
+    23: (b"SPSS_FMT_ADATE", b"Date format dd-mmm-yyyy"),
+    24: (b"SPSS_FMT_JDATE", b"Julian date - yyyyddd"),
+    25: (b"SPSS_FMT_DTIME", b"Date-time dd hh:mm:ss.s"),
+    26: (b"SPSS_FMT_WKDAY", b"Day of the week"),
+    27: (b"SPSS_FMT_MONTH", b"Month"),
+    28: (b"SPSS_FMT_MOYR", b"mmm yyyy"),
+    29: (b"SPSS_FMT_QYR", b"q Q yyyy"),
+    30: (b"SPSS_FMT_WKYR", b"ww WK yyyy"),
+    31: (b"SPSS_FMT_PCT", b"Percent - F followed by %"),
+    32: (b"SPSS_FMT_DOT", b"Like COMMA, switching dot for comma"),
+    33: (b"SPSS_FMT_CCA", b"User Programmable currency format"),
+    34: (b"SPSS_FMT_CCB", b"User Programmable currency format"),
+    35: (b"SPSS_FMT_CCC", b"User Programmable currency format"),
+    36: (b"SPSS_FMT_CCD", b"User Programmable currency format"),
+    37: (b"SPSS_FMT_CCE", b"User Programmable currency format"),
+    38: (b"SPSS_FMT_EDATE", b"Date in dd/mm/yyyy style"),
+    39: (b"SPSS_FMT_SDATE", b"Date in yyyy/mm/dd style")}
 
 MAXLENGTHS = {
     "SPSS_MAX_VARNAME": (64, "Variable name"),

savReaderWriter/header.py

                 checkErrsWarns(msg, retcode)
 
             printFormat = allFormats.get(printFormat_.value)[0]
-            printFormat = printFormat.split("_")[-1]
-            format_ = printFormat + str(printWid_.value)
+            printFormat = printFormat.split(b"_")[-1]
+            format_ = printFormat + bytes(str(printWid_.value))
             if self.varTypes[varName] == 0:
-                format_ += ("." + str(printDec_.value))
-            if format_.endswith(".0"):
+                format_ += (b"." + bytes(str(printDec_.value)))
+            if format_.endswith(b".0"):
                 format_ = format_[:-2]
             self.formats_[varName] = format_
         return self.formats_
         "ratio", "flag", "typeless". This is used in Spss procedures such as
         CTABLES."""
         func = self.spssio.spssGetVarMeasureLevel
-        levels = {0: "unknown", 1: "nominal", 2: "ordinal", 3: "scale",
-                  3: "ratio", 4: "flag", 5: "typeless"}
+        levels = {0: b"unknown", 1: b"nominal", 2: b"ordinal", 3: b"scale",
+                  3: b"ratio", 4: b"flag", 5: b"typeless"}
         measureLevel = c_int()
         varMeasureLevels = {}
         for varName in self.varNames:
         if not varMeasureLevels:
             return
         func = self.spssio.spssSetVarMeasureLevel
-        levels = {"unknown": 0, "nominal": 1, "ordinal": 2, "scale": 3,
-                  "ratio": 3, "flag": 4, "typeless": 5}
+        levels = {b"unknown": 0, b"nominal": 1, b"ordinal": 2, b"scale": 3,
+                  b"ratio": 3, b"flag": 4, b"typeless": 5}
         for varName, level in self.encode(varMeasureLevels).items():
             if level.lower() not in levels:
-                msg = "Valid levels are %"
-                raise ValueError(msg % ", ".join(levels.keys()))
+                msg = "Valid levels are %s"
+                raise ValueError(msg % b", ".join(levels.keys()).decode())
             level = levels.get(level.lower())
             retcode = func(c_int(self.fh), c_char_py3k(varName), c_int(level))
             if retcode:
-                msg = ("Problem setting variable mesasurement level. " +
-                       "Valid levels are: %s")
-                checkErrsWarns(msg % ", ".join(levels.keys()), retcode)
+                msg = "Problem setting variable mesasurement level: '%s'"
+                checkErrsWarns(msg % varName.decode(), retcode)
 
     @property
     @decode
             retcode = func(c_int(self.fh), c_char_py3k(vName),
                            byref(varColumnWidth))
             if retcode:
-                msg = "Problem getting column width: %r" % varName
-                checkErrsWarns(msg, retcode)
+                msg = "Problem getting column width: '%s'"
+                checkErrsWarns(msg % varName.decode(), retcode)
             varColumnWidths[varName] = varColumnWidth.value
         return varColumnWidths
 
             retcode = func(c_int(self.fh), c_char_py3k(varName),
                            c_int(varColumnWidth))
             if retcode:
-                msg = "Error setting variable colunm width"
-                checkErrsWarns(msg, retcode)
+                msg = "Error setting variable column width: '%s'"
+                checkErrsWarns(msg % varName.decode(), retcode)
 
     def _setColWidth10(self):
         """Set the variable display width of string values to at least 10
             # zero = appropriate width determined by spss
             columnWidths[varName] = 10 if 0 < varType < 10 else 0
         self.columnWidths = columnWidths
-        self.measureLevels = dict([(v, "unknown") for v in self.varNames])
-        self.alignments = dict([(v, "left") for v in self.varNames])
+        self.measureLevels = dict([(v, b"unknown") for v in self.varNames])
+        self.alignments = dict([(v, b"left") for v in self.varNames])
 
     @property
     @decode
         alignment, measurement level and column width all need to be set.
         """
         func = self.spssio.spssGetVarAlignment
-        alignments = {0: "left", 1: "right", 2: "center"}
+        alignments = {0: b"left", 1: b"right", 2: b"center"}
         alignment_ = c_int()
         varAlignments = {}
         for varName in self.varNames:
             alignment = alignments[alignment_.value]
             varAlignments[varName] = alignment
             if retcode:
-                msg = "Problem getting variable alignment: %r" % varName
-                checkErrsWarns(msg, retcode)
+                msg = "Problem getting variable alignment: '%s'"
+                checkErrsWarns(msg % varName.decode(), retcode)
         return varAlignments
 
     @alignments.setter
         if not varAlignments:
             return
         func = self.spssio.spssSetVarAlignment
-        alignments = {"left": 0, "right": 1, "center": 2}
+        alignments = {b"left": 0, b"right": 1, b"center": 2}
         for varName, varAlignment in varAlignments.items():
             if varAlignment.lower() not in alignments:
-                msg = "Valid alignments are %"
-                raise ValueError(msg % ", ".join(alignments.keys()))
+                ukeys = b", ".join(alignments.keys()).decode()
+                raise ValueError("Valid alignments are %s" % ukeys)
             alignment = alignments.get(varAlignment.lower())
             retcode = func(c_int(self.fh), c_char_py3k(varName), c_int(alignment))
             if retcode:
-                msg = "Problem setting variable alignment for variable %r"
-                checkErrsWarns(msg % varName, retcode)
+                msg = "Problem setting variable alignment for variable '%s'"
+                checkErrsWarns(msg % varName.decode(), retcode)
 
     @property
     @decode
         if not varSets.value:
             return {}
         varSets_ = {}
-        for varSet in varSets.value.split("\n")[:-1]:
-            k, v = varSet.split("= ")
+        for varSet in varSets.value.split(b"\n")[:-1]:
+            k, v = varSet.split(b"= ")
             varSets_[k] = v.split()
 
         # clean up
             return
         varSets_ = []
         for varName, varSet in varSets.items():
-            varSets_.append("%s= %s" % (varName, " ".join(varSet)))
-        varSets_ = c_char_py3k("\n".join(varSets_))
+            varSets_.append(b"%s= %s" % (varName, " ".join(varSet)))
+        varSets_ = c_char_py3k(b"\n".join(varSets_))
         retcode = self.spssio.spssSetVariableSets(c_int(self.fh), varSets_)
         if retcode:
             msg = "Problem setting variable set information"
         varRoles may be any of the following: 'both', 'frequency', 'input',
         'none', 'partition', 'record ID', 'split', 'target'"""
         func = self.spssio.spssGetVarRole
-        roles = {0: "input", 1: "target", 2: "both", 3: "none", 4: "partition",
-                 5: "split", 6: "frequency", 7: "record ID"}
+        roles = {0: b"input", 1: b"target", 2: b"both", 3: b"none", 4: b"partition",
+                 5: b"split", 6: b"frequency", 7: b"record ID"}
         varRoles = {}
         varRole_ = c_int()
         for varName in self.varNames:
                            byref(attrNamesArr), byref(attrValuesArr),
                            byref(nAttr))
             if retcode:
-                msg = "Problem getting attributes of variable %r (step 1)"
-                checkErrsWarns(msg % varName, retcode)
+                msg = "Problem getting attributes of variable '%s' (step 1/2)"
+                checkErrsWarns(msg % varName.decode(), retcode)
 
             # step 2: get attributes with arrays of proper size
             nAttr = c_int(nAttr.value)
                            byref(attrNamesArr), byref(attrValuesArr),
                            byref(nAttr))
             if retcode:
-                msg = "Problem getting attributes of variable %r (step 2)"
-                checkErrsWarns(msg % varName, retcode)
+                msg = "Problem getting attributes of variable '%s' (step 2/2)"
+                checkErrsWarns(msg % varName.decode(), retcode)
 
             # get array contents
             if not nAttr.value:
             countedValue, lblLen, lblVarNames = matches[0][3:]
         lbl = lblVarNames[:int(lblLen)]
         varNames = lblVarNames[int(lblLen):].split()
-        multRespSet = {setName: {"setType": setType, "label": lbl,
-                                 "varNames": varNames}}
+        multRespSet = {setName: {b"setType": setType, b"label": lbl,
+                                 b"varNames": varNames}}
         if setType == b"D":
-            multRespSet[setName]["countedValue"] = countedValue
+            multRespSet[setName][b"countedValue"] = countedValue
         return multRespSet
 
     def _setMultRespDefs(self, multRespDefs):

savReaderWriter/unit_tests/test_SavHeaderReader_dataDict_namedtuple.py

             self.metadata = header.dataDictionary(True)
 
     def test_alignments(self):
-        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'}
+        alignments = {b'AGE2': b'right',
+                      b'AGE3': b'right',
+                      b'Age': b'left',
+                      b'AvgIncome': b'right',
+                      b'DATE_': b'left',
+                      b'ID': b'left',
+                      b'Income1': b'right',
+                      b'Income2': b'right',
+                      b'Income3': b'center',
+                      b'MONTH_': b'right',
+                      b'MaxIncome': b'right',
+                      b'QUARTER_': b'right',
+                      b'Region': b'left',
+                      b'SEX': b'right',
+                      b'V1': b'right',
+                      b'V2': b'right',
+                      b'V3': b'right',
+                      b'YEAR_': b'right',
+                      b'aLongStringVar': b'left',
+                      b'aShortStringVar': b'left',
+                      b'someDate': b'right',
+                      b'weightVar': b'right'}
         self.assertEqual(self.metadata.alignments, alignments)
 
     def test_caseWeightVar(self):
-        self.assertEqual(self.metadata.caseWeightVar, 'weightVar')
+        self.assertEqual(self.metadata.caseWeightVar, b'weightVar')
 
     def test_columnWidths(self):
-        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}
+        columnWidths = {b'AGE2': 10,
+                        b'AGE3': 10,
+                        b'Age': 10,
+                        b'AvgIncome': 11,
+                        b'DATE_': 10,
+                        b'ID': 10,
+                        b'Income1': 14,
+                        b'Income2': 14,
+                        b'Income3': 15,
+                        b'MONTH_': 8,
+                        b'MaxIncome': 11,
+                        b'QUARTER_': 10,
+                        b'Region': 10,
+                        b'SEX': 10,
+                        b'V1': 10,
+                        b'V2': 10,
+                        b'V3': 10,
+                        b'YEAR_': 10,
+                        b'aLongStringVar': 26,
+                        b'aShortStringVar': 17,
+                        b'someDate': 13,
+                        b'weightVar': 11}
         self.assertEqual(self.metadata.columnWidths, columnWidths)
 
     def test_fileAttributes(self):
-        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'}
+        fileAttributes = {b'$VariableView2[01]': b'name',
+                          b'$VariableView2[02]': b'type',
+                          b'$VariableView2[03]': b'width',
+                          b'$VariableView2[04]': b'decimals',
+                          b'$VariableView2[05]': b'label',
+                          b'$VariableView2[06]': b'values',
+                          b'$VariableView2[07]': b'missing',
+                          b'$VariableView2[08]': b'columns',
+                          b'$VariableView2[09]': b'alignment',
+                          b'$VariableView2[10]': b'measure',
+                          b'$VariableView2[11]': b'role',
+                          b'$VariableView2[12]': b'@Formula',
+                          b'$VariableView2[13]': b'@DerivedFrom',
+                          b'$VariableView2[14]': b'@Notes',
+                          b'VersionNumber': b'1'}
         self.assertEqual(self.metadata.fileAttributes, fileAttributes)
 
     def test_fileLabel(self):
-        self.assertEqual(self.metadata.fileLabel, 'This is a file label')
+        self.assertEqual(self.metadata.fileLabel, b'This is a file label')
 
     def test_formats(self):
-        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'}
+        formats = {b'AGE2': b'F8.2',
+                   b'AGE3': b'F8.2',
+                   b'Age': b'F3',
+                   b'AvgIncome': b'F8.2',
+                   b'DATE_': b'A8',
+                   b'ID': b'N6',
+                   b'Income1': b'F8.2',
+                   b'Income2': b'F8.2',
+                   b'Income3': b'F8.2',
+                   b'MONTH_': b'F2',
+                   b'MaxIncome': b'F8.2',
+                   b'QUARTER_': b'F1',
+                   b'Region': b'F8.2',
+                   b'SEX': b'F8.2',
+                   b'V1': b'F8.2',
+                   b'V2': b'F8.2',
+                   b'V3': b'F8.2',
+                   b'YEAR_': b'F8',
+                   b'aLongStringVar': b'A100',
+                   b'aShortStringVar': b'A1',
+                   b'someDate': b'ADATE40',
+                   b'weightVar': b'F8.2'}
         self.assertEqual(self.metadata.formats, formats)
 
     def test_measureLevels(self):
-        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'}
+        measureLevels = {b'AGE2': b'ratio',
+                         b'AGE3': b'ratio',
+                         b'Age': b'ratio',
+                         b'AvgIncome': b'ratio',
+                         b'DATE_': b'nominal',
+                         b'ID': b'nominal',
+                         b'Income1': b'ratio',
+                         b'Income2': b'ratio',
+                         b'Income3': b'ratio',
+                         b'MONTH_': b'ordinal',
+                         b'MaxIncome': b'ratio',
+                         b'QUARTER_': b'ordinal',
+                         b'Region': b'nominal',
+                         b'SEX': b'nominal',
+                         b'V1': b'nominal',
+                         b'V2': b'nominal',
+                         b'V3': b'nominal',
+                         b'YEAR_': b'ordinal',
+                         b'aLongStringVar': b'nominal',
+                         b'aShortStringVar': b'nominal',
+                         b'someDate': b'ratio',
+                         b'weightVar': b'nominal'}
         self.assertEqual(self.metadata.measureLevels, measureLevels)
 
     @unittest.skip("===========> CHECK THIS LATER!")
     def test_missingValues(self):
         sysmis = -1 * sys.float_info.max
-        missingValues = {'AGE2': {},
-                         'AGE3': {},
-                         'Age': {'lower': 0.0, 'upper': 18.0},
-                         'AvgIncome': {},
-                         'DATE_': {},
-                         'ID': {},
-                         'Income1': {'lower': sysmis, 'upper': -1.0},
-                         'Income2': {'lower': sysmis, 'upper': -1.0, 'value': 999.0},
-                         'Income3': {'values': [999.0, 888.0, 777.0]},
-                         'MONTH_': {},
-                         'MaxIncome': {},
-                         'QUARTER_': {},
-                         'Region': {},
-                         'SEX': {},
-                         'V1': {},
-                         'V2': {},
-                         'V3': {},
-                         'YEAR_': {},
-                         'aLongStringVar': {},
-                         'aShortStringVar': {'values': ['x', 'y']},
-                         'someDate': {},
-                         'weightVar': {}}
+        missingValues = {b'AGE2': {},
+                         b'AGE3': {},
+                         b'Age': {b'lower': 0.0, b'upper': 18.0},
+                         b'AvgIncome': {},
+                         b'DATE_': {},
+                         b'ID': {},
+                         b'Income1': {b'lower': sysmis, b'upper': -1.0},
+                         b'Income2': {b'lower': sysmis, b'upper': -1.0, b'value': 999.0},
+                         b'Income3': {b'values': [999.0, 888.0, 777.0]},
+                         b'MONTH_': {},
+                         b'MaxIncome': {},
+                         b'QUARTER_': {},
+                         b'Region': {},
+                         b'SEX': {},
+                         b'V1': {},
+                         b'V2': {},
+                         b'V3': {},
+                         b'YEAR_': {},
+                         b'aLongStringVar': {},
+                         b'aShortStringVar': {b'values': [b'x', b'y']},
+                         b'someDate': {},
+                         b'weightVar': {}}
         miss = self.metadata.missingValues
-        self.assertAlmostEqual(miss["Income1"]["lower"], sysmis)
-        self.assertAlmostEqual(miss["Income2"]["lower"], sysmis)
+        self.assertAlmostEqual(miss[b"Income1"][b"lower"], sysmis)
+        self.assertAlmostEqual(miss[b"Income2"][b"lower"], sysmis)
 
-        del miss["Income1"]["lower"]
-        del miss["Income2"]["lower"]
-        del missingValues["Income1"]["lower"]
-        del missingValues["Income2"]["lower"]
+        del miss[b"Income1"][b"lower"]
+        del miss[b"Income2"][b"lower"]
+        del missingValues[b"Income1"][b"lower"]
+        del missingValues[b"Income2"][b"lower"]
         self.assertEqual(self.metadata.missingValues, missingValues)
 
     def test_multRespDefs(self):
-        multRespDefs = {'V': {'countedValue': '1',
-                              'label': '',
-                              'setType': 'D',
-                              'varNames': ['V1', 'V2', 'V3']},
-                        'ages': {'label': 'the ages',
-                                 'setType': 'C',
-                                 'varNames': ['Age', 'AGE2', 'AGE3']},
-                        'incomes': {'label': 'three kinds of income',
-                                    'setType': 'C',
-                                    'varNames': ['Income1',
-                                                 'Income2',
-                                                 'Income3',
-                                                 'Age',
-                                                 'AGE2',
-                                                 'AGE3']}}
+        multRespDefs = {b'V': {b'countedValue': b'1',
+                              b'label': b'',
+                              b'setType': b'D',
+                              b'varNames': [b'V1', b'V2', b'V3']},
+                        b'ages': {b'label': b'the ages',
+                                 b'setType': b'C',
+                                 b'varNames': [b'Age', b'AGE2', b'AGE3']},
+                        b'incomes': {b'label': b'three kinds of income',
+                                    b'setType': b'C',
+                                    b'varNames': [b'Income1',
+                                                 b'Income2',
+                                                 b'Income3',
+                                                 b'Age',
+                                                 b'AGE2',
+                                                 b'AGE3']}}
         self.assertEqual(self.metadata.multRespDefs, multRespDefs)
 
     def test_valueLabels(self):
-        valueLabels = {'Age': {27.0: '27 y.o. ', 34.0: '34 y.o.', 50.0: '50 y.o.'},
-                       'aShortStringVar': {'x': 'someValue label'}}
+        valueLabels = {b'Age': {27.0: b'27 y.o. ', 34.0: b'34 y.o.', 50.0: b'50 y.o.'},
+                       b'aShortStringVar': {b'x': b'someValue label'}}
         self.assertEqual(self.metadata.valueLabels, valueLabels)
 
     def test_varAttributes(self):
-        varAttributes = {'AvgIncome': {'DerivedFrom[1]': 'Income1',
-                                       'DerivedFrom[2]': 'Income2',
-                                       'DerivedFrom[3]': 'Income3',
-                                       'Formula': 'mean(Income1, Income2, Income3)'},
-                         'MaxIncome': {'DerivedFrom[1]': 'Income1',
-                                       'DerivedFrom[2]': 'Income2',
-                                       'DerivedFrom[3]': 'Income3',
-                                       'Formula': 'max(Income1, Income2, Income3)'}}
+        varAttributes = {b'AvgIncome': {b'DerivedFrom[1]': b'Income1',
+                                        b'DerivedFrom[2]': b'Income2',
+                                        b'DerivedFrom[3]': b'Income3',
+                                        b'Formula': b'mean(Income1, Income2, Income3)'},
+                         b'MaxIncome': {b'DerivedFrom[1]': b'Income1',
+                                        b'DerivedFrom[2]': b'Income2',
+                                        b'DerivedFrom[3]': b'Income3',
+                                        b'Formula': b'max(Income1, Income2, Income3)'}}
         self.assertEqual(self.metadata.varAttributes, varAttributes)
 
     def test_varLabels(self):
-        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': ''}
+        varLabels = {b'AGE2': b'',
+                     b'AGE3': b'',
+                     b'Age': b'How old are you?',
+                     b'AvgIncome': b'',
+                     b'DATE_': b'Date.  Format:  "MMM YYYY"              ',
+                     b'ID': b'',
+                     b'Income1': b'',
+                     b'Income2': b'',
+                     b'Income3': b'',
+                     b'MONTH_': b'MONTH, period 12',
+                     b'MaxIncome': b'',
+                     b'QUARTER_': b'QUARTER, period 4',
+                     b'Region': b'What region do you live',
+                     b'SEX': b'',
+                     b'V1': b'',
+                     b'V2': b'',
+                     b'V3': b'',
+                     b'YEAR_': b'YEAR, not periodic',
+                     b'aLongStringVar': b'Some mysterious long stringVar',
+                     b'aShortStringVar': b'Some mysterious short stringVar',
+                     b'someDate': b'',
+                     b'weightVar': b''}
         self.assertEqual(self.metadata.varLabels, varLabels)
 
     def test_varNames(self):
-        varNames = ['ID',
-                    'Age',
-                    'Region',
-                    'Income1',
-                    'Income2',
-                    'Income3',
-                    'AvgIncome',
-                    'MaxIncome',
-                    'AGE2',
-                    'AGE3',
-                    'SEX',
-                    'V1',
-                    'V2',
-                    'V3',
-                    'someDate',
-                    'aShortStringVar',
-                    'aLongStringVar',
-                    'weightVar',
-                    'YEAR_',
-                    'QUARTER_',
-                    'MONTH_',
-                    'DATE_']
+        varNames = [b'ID',
+                    b'Age',
+                    b'Region',
+                    b'Income1',
+                    b'Income2',
+                    b'Income3',
+                    b'AvgIncome',
+                    b'MaxIncome',
+                    b'AGE2',
+                    b'AGE3',
+                    b'SEX',
+                    b'V1',
+                    b'V2',
+                    b'V3',
+                    b'someDate',
+                    b'aShortStringVar',
+                    b'aLongStringVar',
+                    b'weightVar',
+                    b'YEAR_',
+                    b'QUARTER_',
+                    b'MONTH_',
+                    b'DATE_']
         self.assertEqual(self.metadata.varNames, varNames)
 
     def test_varRoles(self):
-        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'}
+        varRoles = {b'AGE2': b'input',
+                    b'AGE3': b'input',
+                    b'Age': b'input',
+                    b'AvgIncome': b'input',
+                    b'DATE_': b'input',
+                    b'ID': b'input',
+                    b'Income1': b'target',
+                    b'Income2': b'target',
+                    b'Income3': b'target',
+                    b'MONTH_': b'input',
+                    b'MaxIncome': b'input',
+                    b'QUARTER_': b'input',
+                    b'Region': b'partition',
+                    b'SEX': b'input',
+                    b'V1': b'input',
+                    b'V2': b'input',
+                    b'V3': b'input',
+                    b'YEAR_': b'input',
+                    b'aLongStringVar': b'input',
+                    b'aShortStringVar': b'input',
+                    b'someDate': b'input',
+                    b'weightVar': b'input'}
         self.assertEqual(self.metadata.varRoles, varRoles)
 
     def test_varSets(self):
         self.assertEqual(self.metadata.varSets, {})
 
     def test_varTypes(self):
-        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}
+        varTypes = {b'AGE2': 0,
+                    b'AGE3': 0,
+                    b'Age': 0,
+                    b'AvgIncome': 0,
+                    b'DATE_': 8,
+                    b'ID': 0,
+                    b'Income1': 0,
+                    b'Income2': 0,
+                    b'Income3': 0,
+                    b'MONTH_': 0,
+                    b'MaxIncome': 0,
+                    b'QUARTER_': 0,
+                    b'Region': 0,
+                    b'SEX': 0,
+                    b'V1': 0,
+                    b'V2': 0,
+                    b'V3': 0,
+                    b'YEAR_': 0,
+                    b'aLongStringVar': 100,
+                    b'aShortStringVar': 1,
+                    b'someDate': 0,
+                    b'weightVar': 0}
         self.assertEqual(self.metadata.varTypes, varTypes)
 
 if __name__ == "__main__":