aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests/unit/base/test_general_object.py
diff options
context:
space:
mode:
authoruditgulati2021-01-05 13:13:28 -0600
committeruditgulati2021-01-05 13:13:28 -0600
commit1e7a4d76fa36d1476fe37ae9b4c0a946fe99bce1 (patch)
tree0d18520e09fa0edce0080c773d0edd14750b855c /wqflask/tests/unit/base/test_general_object.py
parente106f5888cb4d761a6dcb71dc0273e461ef3c71a (diff)
parente36d40d64c1cf8476002c46b5c9dba308151f75c (diff)
downloadgenenetwork2-1e7a4d76fa36d1476fe37ae9b4c0a946fe99bce1.tar.gz
Merge branch 'testing' of https://github.com/genenetwork/genenetwork2 into snp_browser_changes
Diffstat (limited to 'wqflask/tests/unit/base/test_general_object.py')
-rw-r--r--wqflask/tests/unit/base/test_general_object.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/wqflask/tests/unit/base/test_general_object.py b/wqflask/tests/unit/base/test_general_object.py
new file mode 100644
index 00000000..00fd3c72
--- /dev/null
+++ b/wqflask/tests/unit/base/test_general_object.py
@@ -0,0 +1,40 @@
+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), "name = test\nvalue = 1\n")
+ self.assertEqual(
+ repr(test_obj), "contents = ['a']\nname = test\nvalue = 1\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)