aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests/base/test_general_object.py
diff options
context:
space:
mode:
authorzsloan2020-07-24 20:16:17 -0500
committerGitHub2020-07-24 20:16:17 -0500
commitf66da35a09cbb8da13cfb142cbe3ff208404970b (patch)
treeb05021c6e7b9f83c63257fec63414ecefa36668e /wqflask/tests/base/test_general_object.py
parent60d8968c4fc2ca15fc9cf2f63c0b34a25f6fb053 (diff)
parent5eb26c5a209f3a3c54cf6fe623e5372188bdd1bc (diff)
downloadgenenetwork2-f66da35a09cbb8da13cfb142cbe3ff208404970b.tar.gz
Merge pull request #409 from BonfaceKilz/Build/add-tests
Build/add tests
Diffstat (limited to 'wqflask/tests/base/test_general_object.py')
-rw-r--r--wqflask/tests/base/test_general_object.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/wqflask/tests/base/test_general_object.py b/wqflask/tests/base/test_general_object.py
new file mode 100644
index 00000000..c7701021
--- /dev/null
+++ b/wqflask/tests/base/test_general_object.py
@@ -0,0 +1,41 @@
+import unittest
+
+from base.GeneralObject import GeneralObject
+
+
+class TestGeneralObjectTests(unittest.TestCase):
+ """
+ Test the GeneralObject base class
+ """
+
+ def test_object_contents(self):
+ """Test whether base contents are stored properly"""
+ test_obj = GeneralObject("a", "b", "c")
+ self.assertEqual("abc", ''.join(test_obj.contents))
+ self.assertEqual(len(test_obj), 0)
+
+ def test_object_dict(self):
+ """Test whether the base class is printed properly"""
+ test_obj = GeneralObject("a", name="test", value=1)
+ self.assertEqual(str(test_obj), "value = 1\nname = test\n")
+ self.assertEqual(
+ repr(test_obj), "value = 1\nname = test\ncontents = ['a']\n")
+ self.assertEqual(len(test_obj), 2)
+ self.assertEqual(test_obj["value"], 1)
+ test_obj["test"] = 1
+ self.assertEqual(test_obj["test"], 1)
+
+ def test_get_attribute(self):
+ "Test that getattr works"
+ test_obj = GeneralObject("a", name="test", value=1)
+ self.assertEqual(getattr(test_obj, "value", None), 1)
+ self.assertEqual(getattr(test_obj, "non-existent", None), None)
+
+ def test_object_comparisons(self):
+ "Test that 2 objects of the same length are equal"
+ test_obj1 = GeneralObject("a", name="test", value=1)
+ test_obj2 = GeneralObject("b", name="test2", value=2)
+ test_obj3 = GeneralObject("a", name="test", x=1, y=2)
+ self.assertTrue(test_obj1 == test_obj2 )
+ self.assertFalse(test_obj1 == test_obj3 )
+