Ejemplo n.º 1
0
    def test_nix_to_odml_empty(self):
        file_name = 'tmp'
        nix_path = os.path.join(self.test_dir, file_name + '.nix')
        odml_path = os.path.join(self.test_dir, file_name + '.xml')

        odml.Property(parent=self.odml_doc.sections[0])

        convert.nixwrite(self.odml_doc, nix_path, nix.FileMode.Overwrite)

        nix_file_r = nix.File.open(nix_path, nix.FileMode.ReadOnly)
        convert.odmlwrite(nix_file_r, odml_path)
        odml_doc = odml.load(odml_path)

        self.assertEqual(len(odml_doc.sections[0].props), 1)

        odml_prop = odml_doc.sections[0].props[0]

        self.assertGreater(len(getattr(odml_prop, "id")), 0)
        self.assertEqual(getattr(odml_prop, "name"), getattr(odml_prop, "id"))
        self.assertEqual(getattr(odml_prop, "values"), [])
        self.assertEqual(getattr(odml_prop, "dtype"), None)
        self.assertEqual(getattr(odml_prop, "definition"), None)
        self.assertEqual(getattr(odml_prop, "unit"), None)
        self.assertEqual(getattr(odml_prop, "uncertainty"), None)
        self.assertEqual(getattr(odml_prop, "reference"), None)
        self.assertEqual(getattr(odml_prop, "dependency"), None)
        self.assertEqual(getattr(odml_prop, "dependency_value"), None)
        self.assertEqual(getattr(odml_prop, "value_origin"), None)

        nix_file_r.close()
Ejemplo n.º 2
0
    def test_odml_to_nix_empty(self):
        file_name = 'tmp'
        nix_path = os.path.join(self.test_dir, file_name + '.nix')

        odml.Property(parent=self.odml_doc.sections[0])

        convert.nixwrite(self.odml_doc, nix_path, 'overwrite')
        nix_file = nix.File.open(nix_path)

        self.assertEqual(len(nix_file.sections[0].sections[0].props), 1)

        nix_prop = nix_file.sections[0].sections[0].props[0]

        self.assertGreater(len(getattr(nix_prop, "id")), 0)
        self.assertEqual(getattr(nix_prop, "name"), getattr(nix_prop, "id"))
        self.assertEqual(getattr(nix_prop, "values"), ())
        self.assertEqual(getattr(nix_prop, "data_type"), np.str_)
        self.assertEqual(getattr(nix_prop, "odml_type"), None)
        self.assertEqual(getattr(nix_prop, "definition"), None)
        self.assertEqual(getattr(nix_prop, "unit"), None)
        self.assertEqual(getattr(nix_prop, "uncertainty"), None)
        self.assertEqual(getattr(nix_prop, "reference"), None)
        self.assertEqual(getattr(nix_prop, "dependency"), None)
        self.assertEqual(getattr(nix_prop, "dependency_value"), None)
        self.assertEqual(getattr(nix_prop, "value_origin"), None)

        nix_file.close()
Ejemplo n.º 3
0
    def test_odml_to_nix_tuple(self):
        file_name_1 = 'tmp' + str(uuid.uuid4())
        nix_path_1 = os.path.join(self.test_dir, file_name_1 + '.nix')
        odml.Property(name='2-tuple property',
                      values=["(1; 2)", "(3; 4)"],
                      parent=self.odml_doc.sections[0],
                      dtype='2-tuple')
        convert.nixwrite(self.odml_doc, nix_path_1, 'overwrite')
        nix_file_1 = nix.File.open(nix_path_1)
        nix_prop_1 = nix_file_1.sections[0].sections[0].props[0]
        vals_1 = nix_prop_1.values
        #assert None, such that backconversion works correctly
        self.assertEqual(getattr(nix_prop_1, "odml_type"), None)
        self.assertEqual(getattr(nix_prop_1, "data_type"), np.str_)
        self.assertEqual(len(vals_1), 2)
        self.assertEqual(vals_1, ("(1; 2)", "(3; 4)"))
        nix_file_1.close()

        file_name_2 = 'tmp' + str(uuid.uuid4())
        nix_path_2 = os.path.join(self.test_dir, file_name_2 + '.nix')
        odml.Property(name='3-tuple property',
                      values=["(1; 2; 3)", "(4; 5; 6)"],
                      parent=self.odml_doc.sections[0],
                      dtype='3-tuple')
        convert.nixwrite(self.odml_doc, nix_path_2, 'overwrite')
        nix_file_2 = nix.File.open(nix_path_2)
        nix_prop_2 = nix_file_2.sections[0].sections[0].props[1]
        vals_2 = nix_prop_2.values
        #assert None, such that backconversion works correctly
        self.assertEqual(getattr(nix_prop_2, "odml_type"), None)
        self.assertEqual(getattr(nix_prop_2, "data_type"), np.str_)
        self.assertEqual(len(vals_2), 2)
        self.assertEqual(vals_2, ("(1; 2; 3)", "(4; 5; 6)"))
        nix_file_2.close()
Ejemplo n.º 4
0
    def test_nix_to_odml_none(self):
        file_name = 'tmp'
        nix_path = os.path.join(self.test_dir, file_name + '.nix')
        odml_path = os.path.join(self.test_dir, file_name + '.xml')

        odml.Section(name=None,
                     oid=None,
                     definition=None,
                     parent=self.odml_doc,
                     type="MustBeSet",
                     reference=None,
                     repository=None,
                     link=None,
                     include=None)

        convert.nixwrite(self.odml_doc, nix_path, nix.FileMode.Overwrite)

        nix_file_r = nix.File.open(nix_path, nix.FileMode.ReadOnly)
        convert.odmlwrite(nix_file_r, odml_path)
        odml_doc = odml.load(odml_path)
        self.assertEqual(len(odml_doc.sections), 1)
        odml_sec = odml_doc.sections[0]

        self.assertGreater(len(getattr(odml_sec, "id")), 0)
        self.assertEqual(getattr(odml_sec, "name"), getattr(odml_sec, "id"))
        self.assertEqual(getattr(odml_sec, "type"), "MustBeSet")
        self.assertEqual(getattr(odml_sec, "definition"), None)
        self.assertEqual(getattr(odml_sec, "reference"), None)
        self.assertEqual(getattr(odml_sec, "repository"), None)
        self.assertEqual(getattr(odml_sec, "link"), None)
        self.assertEqual(getattr(odml_sec, "include"), None)

        nix_file_r.close()
Ejemplo n.º 5
0
    def test_odml_to_nix_none(self):
        file_name = 'tmp'
        nix_path = os.path.join(self.test_dir, file_name + '.nix')

        odml.Section(name=None,
                     oid=None,
                     definition=None,
                     parent=self.odml_doc,
                     type="MustBeSet",
                     reference=None,
                     repository=None,
                     link=None,
                     include=None)

        convert.nixwrite(self.odml_doc, nix_path, 'overwrite')
        nix_file = nix.File.open(nix_path)

        self.assertEqual(len(nix_file.sections[0].sections), 1)

        nix_sec = nix_file.sections[0].sections[0]

        self.assertGreater(len(getattr(nix_sec, "id")), 0)
        self.assertEqual(getattr(nix_sec, "name"), getattr(nix_sec, "id"))
        self.assertEqual(getattr(nix_sec, "type"), "MustBeSet")
        self.assertEqual(getattr(nix_sec, "definition"), None)
        self.assertEqual(getattr(nix_sec, "reference"), None)
        self.assertEqual(getattr(nix_sec, "repository"), None)
        self.assertEqual(getattr(nix_sec, "link"), None)
        #self.assertEqual(getattr(nix_sec, "include"), None)

        nix_file.close()
Ejemplo n.º 6
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()
Ejemplo n.º 7
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()
Ejemplo n.º 8
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()
Ejemplo n.º 9
0
    def test_double_conversion(self):
        nf = os.path.join(self.test_dir, 'tmp.nix')
        of = os.path.join(self.test_dir, 'tmp.odml')
        convert.nixwrite(self.odml_doc, nf, 'overwrite')
        nix_file = nix.File(nf)
        convert.odmlwrite(nix_file, of)
        odml_doc = odml.load(of)

        for attr in document_attributes:
            self.assertEqual(getattr(self.odml_doc, attr), getattr(odml_doc, attr))

        for sec in self.odml_doc.sections:
            sec2 = odml_doc.sections[sec.name]
            for attr in section_attributes:
                self.assertEqual(getattr(sec, attr), getattr(sec2, attr))

            for prop in sec.properties:
                prop2 = sec2.properties[prop.name]
                for attr in property_attributes:
                    self.assertEqual(getattr(prop, attr), getattr(prop2, attr))

        nix_file.close()