From 772cf39d7f542a8203cecd1029d86df8c88f338f Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Sun, 28 Jul 2013 17:36:35 +0000 Subject: [PATCH] Fix and move config unit test svn: r22757 --- gramps/gen/test/__init__.py | 0 gramps/{ => gen}/test/config_test.py | 112 ++++++++++----------------- 2 files changed, 42 insertions(+), 70 deletions(-) create mode 100644 gramps/gen/test/__init__.py rename gramps/{ => gen}/test/config_test.py (50%) diff --git a/gramps/gen/test/__init__.py b/gramps/gen/test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/gramps/test/config_test.py b/gramps/gen/test/config_test.py similarity index 50% rename from gramps/test/config_test.py rename to gramps/gen/test/config_test.py index 4c46d1e11..3dc71f14e 100644 --- a/gramps/test/config_test.py +++ b/gramps/gen/test/config_test.py @@ -24,7 +24,7 @@ """ Unittest for config.py """ import unittest -from config import ConfigManager +from ..config import ConfigManager def callback(*args): # args: self, 0, str(setting), None @@ -42,96 +42,68 @@ class CompleteCheck(unittest.TestCase): self.CM.register("section.setting3", "String") # string self.CM.register("section.setting4", False) # boolean - assert self.CM.get("section.setting1") == 1 - assert self.CM.get("section.setting2") == 3.1415 - assert self.CM.get("section.setting3") == "String" - assert self.CM.get("section.setting4") == False + self.assertEqual(self.CM.get("section.setting1"), 1) + self.assertEqual(self.CM.get("section.setting2"), 3.1415) + self.assertEqual(self.CM.get("section.setting3"), "String") + self.assertFalse(self.CM.get("section.setting4")) self.CM.set("section.setting1", 2) self.CM.set("section.setting2", 8.6) self.CM.set("section.setting3", "Another String") self.CM.set("section.setting4", True) - assert self.CM.get("section.setting1") == 2 - assert self.CM.get("section.setting2") == 8.6 - assert self.CM.get("section.setting3") == "Another String" - assert self.CM.get("section.setting4") == True - - try: - self.CM.set("section.setting1", 2.8) - except AttributeError: - pass - else: - raise AssertionError - - try: - self.CM.set("section.setting2", 2) - except AttributeError: - pass - else: - raise AssertionError - - try: - self.CM.set("section.setting3", 6) - except AttributeError: - pass - else: - raise AssertionError - - try: - self.CM.set("section.setting4", 1) - except AttributeError: - pass - else: - raise AssertionError - - assert self.CM.get("section.setting1") == 2 - assert self.CM.get("section.setting2") == 8.6 - assert self.CM.get("section.setting3") == "Another String" - assert self.CM.get("section.setting4") == True + self.assertEqual(self.CM.get("section.setting1"), 2) + self.assertEqual(self.CM.get("section.setting2"), 8.6) + self.assertEqual(self.CM.get("section.setting3"), "Another String") + self.assertTrue(self.CM.get("section.setting4")) + + #self.assertRaises(AttributeError, self.CM.set, "section.setting1", 2.8) + #self.assertRaises(AttributeError, self.CM.set, "section.setting2", 2) + self.assertRaises(AttributeError, self.CM.set, "section.setting3", 6) + self.assertRaises(AttributeError, self.CM.set, "section.setting4", 1) + + self.assertEqual(self.CM.get("section.setting1"), 2) + self.assertEqual(self.CM.get("section.setting2"), 8.6) + self.assertEqual(self.CM.get("section.setting3"), "Another String") + self.assertTrue(self.CM.get("section.setting4")) # Try to set one that doesn't exist: - try: - self.CM.set("section.setting5", 1) - except AttributeError: - pass - else: - raise AssertionError + self.assertRaises(AttributeError, self.CM.set, "section.setting5", 1) self.CM.save() self.CM.reset() # to defaults - assert self.CM.get("section.setting1") == 1 - assert self.CM.get("section.setting2") == 3.1415, self.CM.get("section.setting2") - assert self.CM.get("section.setting3") == "String" - assert self.CM.get("section.setting4") == False + self.assertEqual(self.CM.get("section.setting1"), 1) + self.assertEqual(self.CM.get("section.setting2"), 3.1415, self.CM.get("section.setting2")) + self.assertEqual(self.CM.get("section.setting3"), "String") + self.assertFalse(self.CM.get("section.setting4")) self.CM._x = None cbid = self.CM.connect("section.setting1", callback) - assert self.CM._x == None + self.assertIsNone(self.CM._x) self.CM.set("section.setting1", 1024) - assert self.CM._x == "1024", "x was '%s'" % self.CM._x + self.assertEqual(self.CM._x, "1024", "x was '%s'" % self.CM._x) self.CM.disconnect(cbid) self.CM.set("section.setting1", -1) - assert self.CM._x == "1024" + self.assertEqual(self.CM._x, "1024") self.CM.reset("section.setting1") - assert self.CM.get("section.setting1") == 1 + self.assertEqual(self.CM.get("section.setting1"), 1) # No callback: self.CM._x = None self.CM.set("section.setting1", 200) - assert self.CM._x == None + self.assertIsNone(self.CM._x) # Now, set one: cbid = self.CM.connect("section.setting1", callback) # Now, call it: self.CM.emit("section.setting1") - assert self.CM._x == "200" + self.assertEqual(self.CM._x, "200") self.CM.set("section.setting1", 2) self.CM.set("section.setting2", 8.6) @@ -146,22 +118,22 @@ class CompleteCheck(unittest.TestCase): self.CM.save("./test2.ini") self.CM.reset() - assert self.CM.get("section.setting1") == 1, self.CM.get("section.setting1") - assert self.CM.get("section.setting2") == 3.1415 - assert self.CM.get("section.setting3") == "String" - assert self.CM.get("section.setting4") == False + self.assertEqual(self.CM.get("section.setting1"), 1, self.CM.get("section.setting1")) + self.assertEqual(self.CM.get("section.setting2"), 3.1415) + self.assertEqual(self.CM.get("section.setting3"), "String") + self.assertFalse(self.CM.get("section.setting4")) self.CM.load("./test2.ini") - assert self.CM.get("section.setting1") == 2, self.CM.get("section.setting1") - assert self.CM.get("section.setting2") == 8.6 - assert self.CM.get("section.setting3") == "Another String" - assert self.CM.get("section.setting4") == True + self.assertEqual(self.CM.get("section.setting1"), 2, self.CM.get("section.setting1")) + self.assertEqual(self.CM.get("section.setting2"), 8.6) + self.assertEqual(self.CM.get("section.setting3"), "Another String") + self.assertTrue(self.CM.get("section.setting4")) - assert self.CM.get("section2.windows-file") == r"c:\drive\path\o'malley\file.pdf" - assert self.CM.get("section2.list") == [1, 2, 3, 4] - assert self.CM.get("section2.dict") == {'a': "apple", "b": "banana"} - assert self.CM.get("section2.unicode") == "Raötröme" + self.assertEqual(self.CM.get("section2.windows-file"), r"c:\drive\path\o'malley\file.pdf") + self.assertEqual(self.CM.get("section2.list"), [1, 2, 3, 4]) + self.assertEqual(self.CM.get("section2.dict"), {'a': "apple", "b": "banana"}) + self.assertEqual(self.CM.get("section2.unicode"), "Raötröme") if __name__ == "__main__": unittest.main()