Skip to content
Snippets Groups Projects
Commit 368bcb3f authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

SW-516: removed test for obsolete convertStringValuesToBuffer. Added test for is_iterable

parent 0a7a4931
No related branches found
No related tags found
No related merge requests found
...@@ -11,45 +11,25 @@ def tearDownModule(): ...@@ -11,45 +11,25 @@ def tearDownModule():
pass pass
class TestUtils(unittest.TestCase): class TestUtils(unittest.TestCase):
def test_string_to_buffer_and_back(self): def test_is_iterable(self):
original = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.' #list
self.assertTrue(is_iterable([]))
d = { 'test-key' : original } self.assertTrue(is_iterable([1, 2, 3]))
#print str(d)
self.assertTrue(isinstance(d['test-key'], str)) #dict
self.assertTrue(is_iterable({}))
d2 = convertStringValuesToBuffer(d, 0) self.assertTrue(is_iterable({1:2, 3:4}))
print(d2)
self.assertTrue(isinstance(d2['test-key'], memoryview)) #tuple
self.assertTrue(is_iterable((1,2,4)))
d3 = convertBufferValuesToString(d2)
print(d3) #string
self.assertTrue(isinstance(d3['test-key'], str)) self.assertTrue(is_iterable("abc"))
self.assertEqual(original, d3['test-key'])
# non-iterale types
#try conversion again but only for long strings self.assertFalse(is_iterable(1))
d2 = convertStringValuesToBuffer(d, 10000) self.assertFalse(is_iterable(None))
print(d2)
#type should still be basestring (so no conversion happened)
self.assertTrue(isinstance(d2['test-key'], str))
d3 = convertBufferValuesToString(d2)
print(d3)
#type should still be basestring (so no conversion back was needed)
self.assertTrue(isinstance(d3['test-key'], str))
self.assertEqual(original, d3['test-key'])
#try with nested dict
d4 = { 'outer': d }
d2 = convertStringValuesToBuffer(d4, 0)
print(d2)
self.assertTrue(isinstance(d2['outer']['test-key'], memoryview))
d3 = convertBufferValuesToString(d2)
print(d3)
self.assertTrue(isinstance(d3['outer']['test-key'], str))
self.assertEqual(original, d3['outer']['test-key'])
def main(argv): def main(argv):
unittest.main() unittest.main()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment