readelf: print addend for RELA relocations without symbol (#292)
[pyelftools.git] / test / test_utils.py
index 00e6137e5ab3a63572741d7edea8a1dbf1ff8fc5..23669e73091254774df74e513d6caed4a578e3d2 100644 (file)
@@ -4,15 +4,11 @@
 # Eli Bendersky (eliben@gmail.com)
 # This code is in the public domain
 #-------------------------------------------------------------------------------
-try:
-    import unittest2 as unittest
-except ImportError:
-    import unittest
+import unittest
 from random import randint
 
-from test.utils import setup_syspath; setup_syspath()
 from elftools.common.py3compat import int2byte, BytesIO
-from elftools.common.utils import (parse_cstring_from_stream,
+from elftools.common.utils import (parse_cstring_from_stream, merge_dicts,
         preserve_stream_pos)
 
 
@@ -45,21 +41,28 @@ class Test_parse_cstring_from_stream(unittest.TestCase):
         self.assertEqual(parse_cstring_from_stream(sio, 2348), text[2348:5000])
 
 
-class Test_preserve_stream_pos(object):
+class Test_preserve_stream_pos(unittest.TestCase):
     def test_basic(self):
-        sio = BytesIO('abcdef')
+        sio = BytesIO(b'abcdef')
         with preserve_stream_pos(sio):
             sio.seek(4)
-        self.assertEqual(stream.tell(), 0)
+        self.assertEqual(sio.tell(), 0)
 
         sio.seek(5)
         with preserve_stream_pos(sio):
             sio.seek(0)
-        self.assertEqual(stream.tell(), 5)
+        self.assertEqual(sio.tell(), 5)
 
 
-if __name__ == '__main__':
-    unittest.main()
+class Test_merge_dicts(unittest.TestCase):
+    def test_basic(self):
+        md = merge_dicts({10: 20, 20: 30}, {30: 40, 50: 60})
+        self.assertEqual(md, {10: 20, 20: 30, 30: 40, 50: 60})
 
+    def test_keys_resolve(self):
+        md = merge_dicts({10: 20, 20: 30}, {20: 40, 50: 60})
+        self.assertEqual(md, {10: 20, 20: 40, 50: 60})
 
 
+if __name__ == '__main__':
+    unittest.main()