about summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-26 20:34:18 +0100
committerhut <hut@lavabit.com>2010-01-26 20:34:18 +0100
commit11d09d02d3168fd6e264de9a5f649bcb6d95af95 (patch)
tree2d35105a56491e685a09ed9f6e717201fed4d438 /test
parent64649898c66f8afb35e01eff8280e46d90fb73ae (diff)
downloadranger-11d09d02d3168fd6e264de9a5f649bcb6d95af95.tar.gz
added testcase for openstruct
Diffstat (limited to 'test')
-rw-r--r--test/tc_ext.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/tc_ext.py b/test/tc_ext.py
index ea82bbfe..2ee4a407 100644
--- a/test/tc_ext.py
+++ b/test/tc_ext.py
@@ -89,6 +89,32 @@ class TestCases(unittest.TestCase):
 		# self.assertEqual('/media/foo',
 		#     mount_path('/media/bar/some_link_to_a_foo_subdirectory'))
 
+	def test_openstruct(self):
+		from ranger.ext.openstruct import OpenStruct
+		from random import randint, choice
+		from string import ascii_letters
+
+		os = OpenStruct(a='a')
+		self.assertEqual(os.a, 'a')
+		self.assertRaises(AttributeError, getattr, os, 'b')
+
+		dictionary = {'foo': 'bar', 'zoo': 'zar'}
+		os = OpenStruct(dictionary)
+		self.assertEqual(os.foo, 'bar')
+		self.assertEqual(os.zoo, 'zar')
+		self.assertRaises(AttributeError, getattr, os, 'sdklfj')
+
+		for i in range(100):
+			attr_name = ''.join(choice(ascii_letters) \
+				for x in range(randint(3,9)))
+			value = randint(100,999)
+			if not attr_name in os:
+				self.assertRaises(AttributeError, getattr, os, attr_name)
+			setattr(os, attr_name, value)
+			value2 = randint(100,999)
+			setattr(os, attr_name, value2)
+			self.assertEqual(value2, getattr(os, attr_name))
+
 
 if __name__ == '__main__':
 	unittest.main()