|
1 | 1 | import unittest |
2 | 2 |
|
| 3 | +import datetime |
| 4 | + |
3 | 5 | from odml import Property, Section, Document, DType |
4 | 6 | from odml.property import BaseProperty |
5 | 7 | from odml.section import BaseSection |
@@ -115,6 +117,19 @@ def test_value(self): |
115 | 117 | self.assertEqual(p5.value, [0]) |
116 | 118 | self.assertEqual(p5.values, [0]) |
117 | 119 |
|
| 120 | + with self.assertRaises(ValueError): |
| 121 | + Property(name="dateprop", dtype=DType.date, value=['20190707']) |
| 122 | + |
| 123 | + with self.assertRaises(ValueError): |
| 124 | + Property(name="timeprop", dtype=DType.time, value=['11.11.11']) |
| 125 | + |
| 126 | + with self.assertRaises(ValueError): |
| 127 | + Property(name="datetimeprop", dtype=DType.datetime, value=['20190707']) |
| 128 | + |
| 129 | + with self.assertRaises(ValueError): |
| 130 | + Property(name="intprop", dtype=DType.int, value=[2, "Hello!", 4]) |
| 131 | + |
| 132 | + |
118 | 133 | def test_value_append(self): |
119 | 134 | # Test append w/o Property value or dtype |
120 | 135 | prop = Property(name="append") |
@@ -733,6 +748,42 @@ def test_comparison(self): |
733 | 748 | prop_b.name = 'newPropertyName' |
734 | 749 | self.assertNotEqual(prop_a, prop_b) |
735 | 750 |
|
| 751 | + def test_export_leaf(self): |
| 752 | + doc = Document() |
| 753 | + first = doc.create_section("first") |
| 754 | + second = first.create_section("second") |
| 755 | + first.create_section("third") |
| 756 | + |
| 757 | + name = "prop1" |
| 758 | + values = [1.3] |
| 759 | + first.create_property(name, value=values) |
| 760 | + |
| 761 | + name = "prop2" |
| 762 | + values = ["words"] |
| 763 | + second.create_property(name, value=values) |
| 764 | + |
| 765 | + name = "prop3" |
| 766 | + values = ["a", "b"] |
| 767 | + second.create_property(name, value=values) |
| 768 | + |
| 769 | + name = "prop4" |
| 770 | + values = [3] |
| 771 | + second.create_property(name, value=values) |
| 772 | + |
| 773 | + name = "prop5" |
| 774 | + values = ["abc"] |
| 775 | + first.create_property(name, value=values) |
| 776 | + |
| 777 | + ex1 = first.properties["prop1"].export_leaf() |
| 778 | + self.assertEqual(len(ex1['first'].properties), 1) |
| 779 | + self.assertEqual(len(ex1['first'].sections), 0) |
| 780 | + |
| 781 | + ex2 = second.properties["prop2"].export_leaf() |
| 782 | + self.assertEqual(len(ex2.sections), 1) |
| 783 | + self.assertEqual(len(ex2['first'].properties), 2) |
| 784 | + self.assertEqual(len(ex2['first'].sections), 1) |
| 785 | + self.assertEqual(len(ex2['first']['second'].properties), 1) |
| 786 | + |
736 | 787 |
|
737 | 788 | if __name__ == "__main__": |
738 | 789 | print("TestProperty") |
|
0 commit comments