Beispiel #1
0
    def test_nix_to_odml_datetime(self):
        file_name_1 = 'tmp' + str(uuid.uuid4())
        nix_path_1 = os.path.join(self.test_dir, file_name_1 + '.nix')
        nix_file_1 = nix.File.open(nix_path_1, nix.FileMode.Overwrite)
        odml_path_1 = os.path.join(self.test_dir, file_name_1 + '.xml')

        sec_1 = nix_file_1.create_section(name="section")
        prop_1 = sec_1.create_property(name="datetime property",
                                       values_or_dtype="datetime")
        prop_1.values = [
            '2011-11-01 11:11:11', '2012-12-02 02:02:02', '2012-12-03T03:03:03'
        ]

        convert.odmlwrite(nix_file_1, odml_path_1)
        odml_doc_1 = odml.load(odml_path_1)

        odml_prop_1 = odml_doc_1.sections[0].props[0]
        vals_1 = odml_prop_1.values
        self.assertEqual(getattr(odml_prop_1, "dtype"), odml.DType.datetime)
        self.assertEqual(len(vals_1), 3)
        self.assertEqual(vals_1, [
            datetime.datetime(2011, 11, 1, 11, 11, 11),
            datetime.datetime(2012, 12, 2, 2, 2, 2),
            datetime.datetime(2012, 12, 3, 3, 3, 3)
        ])
        nix_file_1.close()

        file_name_2 = 'tmp' + str(uuid.uuid4())
        nix_path_2 = os.path.join(self.test_dir, file_name_2 + '.nix')
        nix_file_2 = nix.File.open(nix_path_2, nix.FileMode.Overwrite)
        odml_path_2 = os.path.join(self.test_dir, file_name_2 + '.xml')

        sec_2 = nix_file_2.create_section(name="section")

        prop_2 = sec_2.create_property(name="datetime property 2",
                                       values_or_dtype=np.str_)
        prop_2.values = [
            '2012-12-02 12:12:12', '2013-01-01 01:01:01', '2013-01-02T02:02:02'
        ]
        setattr(prop_2, "odml_type", nix.OdmlType("datetime"))

        convert.odmlwrite(nix_file_2, odml_path_2)
        odml_doc_2 = odml.load(odml_path_2)

        odml_prop_2 = odml_doc_2.sections[0].props[0]
        vals = odml_prop_2.values
        self.assertEqual(getattr(odml_prop_2, "dtype"), odml.DType.datetime)
        self.assertEqual(len(vals), 3)
        self.assertEqual(vals, [
            datetime.datetime(2012, 12, 2, 12, 12, 12),
            datetime.datetime(2013, 1, 1, 1, 1, 1),
            datetime.datetime(2013, 1, 2, 2, 2, 2)
        ])
        nix_file_2.close()
Beispiel #2
0
 def test_odml_to_nix_int(self):
     file_name = 'tmp' + str(uuid.uuid4())
     nix_path = os.path.join(self.test_dir, file_name + '.nix')
     odml.Property(name='int property',
                   values=[1, 2, 3],
                   parent=self.odml_doc.sections[0],
                   dtype='int')
     convert.nixwrite(self.odml_doc, nix_path, 'overwrite')
     nix_file = nix.File.open(nix_path)
     nix_prop = nix_file.sections[0].sections[0].props[0]
     vals = nix_prop.values
     self.assertEqual(getattr(nix_prop, "odml_type"), nix.OdmlType("int"))
     self.assertEqual(getattr(nix_prop, "data_type"), np.int64)
     self.assertEqual(len(vals), 3)
     self.assertEqual(vals, (1, 2, 3))
     nix_file.close()
Beispiel #3
0
 def test_odml_to_nix_time(self):
     file_name = 'tmp' + str(uuid.uuid4())
     nix_path = os.path.join(self.test_dir, file_name + '.nix')
     odml.Property(name='time property',
                   values=[datetime.time(11, 11, 11), '02:02:02'],
                   parent=self.odml_doc.sections[0],
                   dtype='time')
     convert.nixwrite(self.odml_doc, nix_path, 'overwrite')
     nix_file = nix.File.open(nix_path)
     nix_prop = nix_file.sections[0].sections[0].props[0]
     vals = nix_prop.values
     self.assertEqual(getattr(nix_prop, "odml_type"), nix.OdmlType("time"))
     self.assertEqual(getattr(nix_prop, "data_type"), np.str_)
     self.assertEqual(len(vals), 2)
     self.assertEqual(vals, ('11:11:11', '02:02:02'))
     nix_file.close()
Beispiel #4
0
 def test_odml_to_nix_boolean(self):
     file_name = 'tmp' + str(uuid.uuid4())
     nix_path = os.path.join(self.test_dir, file_name + '.nix')
     odml.Property(name='boolean property',
                   values=[True, False, 1],
                   parent=self.odml_doc.sections[0],
                   dtype='boolean')
     convert.nixwrite(self.odml_doc, nix_path, 'overwrite')
     nix_file = nix.File.open(nix_path)
     nix_prop = nix_file.sections[0].sections[0].props[0]
     vals = nix_prop.values
     self.assertEqual(getattr(nix_prop, "odml_type"),
                      nix.OdmlType("boolean"))
     self.assertEqual(getattr(nix_prop, "data_type"), np.bool_)
     self.assertEqual(len(vals), 3)
     self.assertEqual(vals, (True, False, 1))
     nix_file.close()
Beispiel #5
0
    def test_nix_to_odml_string(self):
        file_name_1 = 'tmp' + str(uuid.uuid4())
        nix_path_1 = os.path.join(self.test_dir, file_name_1 + '.nix')
        nix_file_1 = nix.File.open(nix_path_1, nix.FileMode.Overwrite)
        odml_path_1 = os.path.join(self.test_dir, file_name_1 + '.xml')

        sec_1 = nix_file_1.create_section(name="section")
        prop_1 = sec_1.create_property(name="string property",
                                       values_or_dtype=np.str_)
        prop_1.values = ['a', 'b', 'c']

        convert.odmlwrite(nix_file_1, odml_path_1)
        odml_doc_1 = odml.load(odml_path_1)

        odml_prop_1 = odml_doc_1.sections[0].props[0]
        vals_1 = odml_prop_1.values
        self.assertEqual(getattr(odml_prop_1, "dtype"), odml.DType.string)
        self.assertEqual(len(vals_1), 3)
        self.assertEqual(vals_1, ['a', 'b', 'c'])
        nix_file_1.close()

        file_name_2 = 'tmp' + str(uuid.uuid4())
        nix_path_2 = os.path.join(self.test_dir, file_name_2 + '.nix')
        nix_file_2 = nix.File.open(nix_path_2, nix.FileMode.Overwrite)
        odml_path_2 = os.path.join(self.test_dir, file_name_2 + '.xml')

        sec_2 = nix_file_2.create_section(name="section")

        prop_2 = sec_2.create_property(name="string property 2",
                                       values_or_dtype=np.str_)
        prop_2.values = ['d', 'e', 'f']
        setattr(prop_2, "odml_type", nix.OdmlType("string"))

        convert.odmlwrite(nix_file_2, odml_path_2)
        odml_doc_2 = odml.load(odml_path_2)

        odml_prop_2 = odml_doc_2.sections[0].props[0]
        vals = odml_prop_2.values
        self.assertEqual(getattr(odml_prop_2, "dtype"), odml.DType.string)
        self.assertEqual(len(vals), 3)
        self.assertEqual(vals, ["d", "e", "f"])
        nix_file_2.close()
Beispiel #6
0
    def test_nix_to_odml_boolean(self):
        file_name_1 = 'tmp' + str(uuid.uuid4())
        nix_path_1 = os.path.join(self.test_dir, file_name_1 + '.nix')
        nix_file_1 = nix.File.open(nix_path_1, nix.FileMode.Overwrite)
        odml_path_1 = os.path.join(self.test_dir, file_name_1 + '.xml')

        sec_1 = nix_file_1.create_section(name="section")
        prop_1 = sec_1.create_property(name="boolean property",
                                       values_or_dtype=np.bool_)
        prop_1.values = [True, False, True]

        convert.odmlwrite(nix_file_1, odml_path_1)
        odml_doc_1 = odml.load(odml_path_1)

        odml_prop_1 = odml_doc_1.sections[0].props[0]
        vals_1 = odml_prop_1.values
        self.assertEqual(getattr(odml_prop_1, "dtype"), odml.DType.boolean)
        self.assertEqual(len(vals_1), 3)
        self.assertEqual(vals_1, [True, False, True])
        nix_file_1.close()

        file_name_2 = 'tmp' + str(uuid.uuid4())
        nix_path_2 = os.path.join(self.test_dir, file_name_2 + '.nix')
        nix_file_2 = nix.File.open(nix_path_2, nix.FileMode.Overwrite)
        odml_path_2 = os.path.join(self.test_dir, file_name_2 + '.xml')

        sec_2 = nix_file_2.create_section(name="section")

        prop_2 = sec_2.create_property(name="string boolean property",
                                       values_or_dtype=np.str_)
        prop_2.values = ["True", "False", "TRUE", "FALSE"]

        convert.odmlwrite(nix_file_2, odml_path_2)
        odml_doc_2 = odml.load(odml_path_2)

        odml_prop_2 = odml_doc_2.sections[0].props[0]
        vals = odml_prop_2.values
        self.assertEqual(getattr(odml_prop_2, "dtype"), odml.DType.boolean)
        self.assertEqual(len(vals), 4)
        self.assertEqual(vals, [True, False, True, False])
        nix_file_2.close()

        file_name_3 = 'tmp' + str(uuid.uuid4())
        nix_path_3 = os.path.join(self.test_dir, file_name_3 + '.nix')
        nix_file_3 = nix.File.open(nix_path_3, nix.FileMode.Overwrite)
        odml_path_3 = os.path.join(self.test_dir, file_name_3 + '.xml')

        sec_3 = nix_file_3.create_section(name="section")

        prop_3 = sec_3.create_property(name="boolean property 3",
                                       values_or_dtype=np.bool_)
        prop_3.values = [False, True, False]
        setattr(prop_3, "odml_type", nix.OdmlType("boolean"))

        convert.odmlwrite(nix_file_3, odml_path_3)
        odml_doc_3 = odml.load(odml_path_3)

        odml_prop_3 = odml_doc_3.sections[0].props[0]
        vals = odml_prop_3.values
        self.assertEqual(getattr(odml_prop_3, "dtype"), odml.DType.boolean)
        self.assertEqual(len(vals), 3)
        self.assertEqual(vals, [False, True, False])
        nix_file_3.close()
Beispiel #7
0
    def test_nix_to_odml_int(self):
        file_name_1 = 'tmp' + str(uuid.uuid4())
        nix_path_1 = os.path.join(self.test_dir, file_name_1 + '.nix')
        nix_file_1 = nix.File.open(nix_path_1, nix.FileMode.Overwrite)
        odml_path_1 = os.path.join(self.test_dir, file_name_1 + '.xml')

        sec_1 = nix_file_1.create_section(name="section")
        prop_1 = sec_1.create_property(name="int property",
                                       values_or_dtype=np.int64)
        prop_1.values = [1, 2, 3]

        convert.odmlwrite(nix_file_1, odml_path_1)
        odml_doc_1 = odml.load(odml_path_1)

        odml_prop_1 = odml_doc_1.sections[0].props[0]
        vals_1 = odml_prop_1.values
        self.assertEqual(getattr(odml_prop_1, "dtype"), odml.DType.int)
        self.assertEqual(len(vals_1), 3)
        self.assertEqual(vals_1, [1, 2, 3])
        nix_file_1.close()

        file_name_2 = 'tmp' + str(uuid.uuid4())
        nix_path_2 = os.path.join(self.test_dir, file_name_2 + '.nix')
        nix_file_2 = nix.File.open(nix_path_2, nix.FileMode.Overwrite)
        odml_path_2 = os.path.join(self.test_dir, file_name_2 + '.xml')

        sec_2 = nix_file_2.create_section(name="section")

        prop_2 = sec_2.create_property(name="string int property",
                                       values_or_dtype=np.str_)
        prop_2.values = ["4", "5", "6"]

        convert.odmlwrite(nix_file_2, odml_path_2)
        odml_doc_2 = odml.load(odml_path_2)

        odml_prop_2 = odml_doc_2.sections[0].props[0]
        vals = odml_prop_2.values
        self.assertEqual(getattr(odml_prop_2, "dtype"), odml.DType.int)
        self.assertEqual(len(vals), 3)
        self.assertEqual(vals, [4, 5, 6])
        nix_file_2.close()

        file_name_3 = 'tmp' + str(uuid.uuid4())
        nix_path_3 = os.path.join(self.test_dir, file_name_3 + '.nix')
        nix_file_3 = nix.File.open(nix_path_3, nix.FileMode.Overwrite)
        odml_path_3 = os.path.join(self.test_dir, file_name_3 + '.xml')

        sec_3 = nix_file_3.create_section(name="section")

        prop_3 = sec_3.create_property(name="int property 3",
                                       values_or_dtype=np.int64)
        prop_3.values = [7, 8, 9]
        setattr(prop_3, "odml_type", nix.OdmlType("int"))

        convert.odmlwrite(nix_file_3, odml_path_3)
        odml_doc_3 = odml.load(odml_path_3)

        odml_prop_3 = odml_doc_3.sections[0].props[0]
        vals = odml_prop_3.values
        self.assertEqual(getattr(odml_prop_3, "dtype"), odml.DType.int)
        self.assertEqual(len(vals), 3)
        self.assertEqual(vals, [7, 8, 9])
        nix_file_3.close()