def test_load_from_during_init(self): def generate_doc(): doc = odml.Document() doc.append(odml.Section('mysection')) doc[0].append(odml.Property('myproperty', values=17)) return doc # test loading from odml doc and odml doc generator OdmlTable(generate_doc()) OdmlTable(generate_doc) # saving to test load_from with filepath # generate odml table = OdmlTable(generate_doc) table.write2odml(save_to=self.filename + '.odml') # generate xls table = OdmlXlsTable(generate_doc) table.write2file(save_to=self.filename + '.xls') # generate csv table = OdmlCsvTable(generate_doc) table.write2file(save_to=self.filename + '.csv') # loading from files OdmlTable(self.filename + '.odml') OdmlTable(self.filename + '.xls') OdmlTable(self.filename + '.csv')
def test_load_from_file(self): self.filetype = 'odml' table = OdmlTable() table.load_from_function(create_small_test_odml) dict_in = copy.deepcopy(table._odmldict) table.write2odml(self.filename + '.' + self.filetype) new_test_table = OdmlTable(self.filename + '.' + self.filetype) dict_out = new_test_table._odmldict self.assertEqual(dict_in, dict_out)
def test_load_from_file(self): self.filetype = "odml" table = OdmlTable() table.load_from_function(create_small_test_odml) dict_in = copy.deepcopy(table._odmldict) table.write2odml(self.filename + "." + self.filetype) new_test_table = OdmlTable(self.filename + "." + self.filetype) dict_out = new_test_table._odmldict self.assertEquals(dict_in, dict_out)
class TestLoadSaveOdml(unittest.TestCase): """ class to test loading the odml """ def setUp(self): self.test_table = OdmlTable() self.expected_odmldict = [{'PropertyDefinition': None, 'SectionName': 'section1', 'PropertyName': 'property1', 'Value': 'bla', 'odmlDatatype': 'text', 'DataUnit': None, 'SectionType': 'undefined', 'ValueDefinition': None, 'DataUncertainty': None, 'SectionDefinition': None, 'Path': '/section1'}] def test_load_from_file(self): """ test loading the odml-dictionary from an odml-file """ filename = 'tmp_testfile.odml' doc = create_small_test_odml() odml.tools.xmlparser.XMLWriter(doc).write_file(filename) self.test_table.load_from_file(filename) os.remove(filename) self.assertEqual(self.test_table._odmldict, self.expected_odmldict) def test_load_from_function(self): """ test loading the odml-dictionary from a function that generates an odml-document in python """ self.test_table.load_from_function(create_small_test_odml) self.assertEqual(self.test_table._odmldict, self.expected_odmldict) def test_load_from_odmldoc(self): """ test loading the odml-dictionary from an odml-document in python """ doc = create_small_test_odml() self.test_table.load_from_odmldoc(doc) self.assertEqual(self.test_table._odmldict, self.expected_odmldict) def test_write2odml(self): """ test writing the odmldict back to an odml-file """ file1 = 'test.odml' file2 = 'test2.odml' doc = create_showall_test_odml() self.test_table.load_from_odmldoc(doc) odml.tools.xmlparser.XMLWriter(doc).write_file(file1) self.test_table.change_header(Path=1, SectionName=2, SectionType=3, SectionDefinition=4, PropertyName=5, PropertyDefinition=6, Value=7, ValueDefinition=8, DataUnit=9, DataUncertainty=10, odmlDatatype=11) self.test_table.write2odml(file2) self.test_table.load_from_file(file1) expected = self.test_table._odmldict self.test_table.load_from_file(file2) self.assertEqual(expected, self.test_table._odmldict) os.remove(file1) os.remove(file2)
class TestLoadSaveOdml(unittest.TestCase): """ class to test loading the odml """ def setUp(self): self.test_table = OdmlTable() self.expected_odmldict = [{ 'PropertyDefinition': None, 'Value': ['bla'], 'odmlDatatype': 'text', 'DataUnit': None, 'SectionType': 'n.s.', 'DataUncertainty': None, 'SectionDefinition': None, 'Path': '/section1:property1' }] def test_load_from_file(self): """ test loading the odml-dictionary from an odml-file """ filename = 'tmp_testfile.odml' doc = create_small_test_odml() odml.tools.xmlparser.XMLWriter(doc).write_file(filename) self.test_table.load_from_file(filename) os.remove(filename) self.assertDictEqual(self.test_table._odmldict[0], self.expected_odmldict[0]) def test_load_from_function(self): """ test loading the odml-dictionary from a function that generates an odml-document in python """ self.test_table.load_from_function(create_small_test_odml) self.assertEqual(self.test_table._odmldict, self.expected_odmldict) def test_load_from_odmldoc(self): """ test loading the odml-dictionary from an odml-document in python """ doc = create_small_test_odml() self.test_table.load_from_odmldoc(doc) self.assertEqual(self.test_table._odmldict, self.expected_odmldict) def test_write2odml(self): """ test writing the odmldict back to an odml-file """ file1 = 'test.odml' file2 = 'test2.odml' doc = create_showall_test_odml() self.test_table.load_from_odmldoc(doc) odml.tools.xmlparser.XMLWriter(doc).write_file(file1) self.test_table.change_header(Path=1, SectionName=2, SectionType=3, SectionDefinition=4, PropertyName=5, PropertyDefinition=6, Value=7, DataUnit=9, DataUncertainty=10, odmlDatatype=11) self.test_table.write2odml(file2) self.test_table.load_from_file(file1) expected = self.test_table._odmldict self.test_table.load_from_file(file2) self.assertEqual(expected, self.test_table._odmldict) os.remove(file1) os.remove(file2)
class TestLoadSaveOdml(unittest.TestCase): """ class to test loading the odml """ def setUp(self): self.test_table = OdmlTable() self.expected_odmldict = [ { "PropertyDefinition": None, "SectionName": "section1", "PropertyName": "property1", "Value": "bla", "odmlDatatype": "text", "DataUnit": None, "SectionType": "undefined", "ValueDefinition": None, "DataUncertainty": None, "SectionDefinition": None, "Path": "/section1", } ] def test_load_from_file(self): """ test loading the odml-dictionary from an odml-file """ filename = "tmp_testfile.odml" doc = create_small_test_odml() odml.tools.xmlparser.XMLWriter(doc).write_file(filename) self.test_table.load_from_file(filename) os.remove(filename) self.assertEqual(self.test_table._odmldict, self.expected_odmldict) def test_load_from_function(self): """ test loading the odml-dictionary from a function that generates an odml-document in python """ self.test_table.load_from_function(create_small_test_odml) self.assertEqual(self.test_table._odmldict, self.expected_odmldict) def test_load_from_odmldoc(self): """ test loading the odml-dictionary from an odml-document in python """ doc = create_small_test_odml() self.test_table.load_from_odmldoc(doc) self.assertEqual(self.test_table._odmldict, self.expected_odmldict) def test_write2odml(self): """ test writing the odmldict back to an odml-file """ file1 = "test.odml" file2 = "test2.odml" doc = create_showall_test_odml() self.test_table.load_from_odmldoc(doc) odml.tools.xmlparser.XMLWriter(doc).write_file(file1) self.test_table.change_header( Path=1, SectionName=2, SectionType=3, SectionDefinition=4, PropertyName=5, PropertyDefinition=6, Value=7, ValueDefinition=8, DataUnit=9, DataUncertainty=10, odmlDatatype=11, ) self.test_table.write2odml(file2) self.test_table.load_from_file(file1) expected = self.test_table._odmldict self.test_table.load_from_file(file2) self.assertEqual(expected, self.test_table._odmldict) os.remove(file1) os.remove(file2)