Rev 102: Add a 'refs_as_list' function. in http://bazaar.launchpad.net/~meliae-dev/meliae/trunk

John Arbash Meinel john at arbash-meinel.com
Thu Oct 22 22:30:03 BST 2009


At http://bazaar.launchpad.net/~meliae-dev/meliae/trunk

------------------------------------------------------------
revno: 102
revision-id: john at arbash-meinel.com-20091022212953-jq44i34175i5by8f
parent: john at arbash-meinel.com-20091020202715-07r2ahx4p2kw0n62
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Thu 2009-10-22 16:29:53 -0500
message:
  Add a 'refs_as_list' function.
-------------- next part --------------
=== modified file 'meliae/loader.py'
--- a/meliae/loader.py	2009-10-20 20:27:15 +0000
+++ b/meliae/loader.py	2009-10-22 21:29:53 +0000
@@ -395,6 +395,21 @@
             as_dict[key] = val
         return as_dict
 
+    def refs_as_list(self, obj):
+        """Expand the ref list, considering it to be a list structure."""
+        as_list = []
+        ref_list = obj.ref_list
+        for addr in ref_list:
+            val = self.objs[addr]
+            if val.type_str == 'bool':
+                val = (val.value == 'True')
+            elif val.value is not None:
+                val = val.value
+            elif val.type_str == 'NoneType':
+                val = None
+            as_list.append(val)
+        return as_list
+
 
 
 def load(source, using_json=None, show_prog=True):

=== modified file 'meliae/tests/test_loader.py'
--- a/meliae/tests/test_loader.py	2009-10-17 03:01:58 +0000
+++ b/meliae/tests/test_loader.py	2009-10-22 21:29:53 +0000
@@ -224,8 +224,7 @@
         self.assertEqual([11, 0], mymod_dict.ref_list)
 
     def test_collapse_instance_dicts(self):
-        lines = list(_instance_dump)
-        manager = loader.load(lines, show_prog=False)
+        manager = loader.load(_instance_dump, show_prog=False)
         # This should collapse all of the references from the instance's dict
         # @2 into the instance @1
         instance = manager.objs[1]
@@ -253,8 +252,7 @@
         self.assertFalse(15 in manager.objs)
 
     def test_expand_refs_as_dict(self):
-        lines = list(_instance_dump)
-        manager = loader.load(lines, show_prog=False)
+        manager = loader.load(_instance_dump, show_prog=False)
         as_dict = manager.refs_as_dict(manager[15])
         self.assertEqual({1: 'c', 'b': 'c'}, as_dict)
         manager.compute_referrers()
@@ -262,3 +260,7 @@
         self.assertEqual({1: 'c', 'b': 'c'}, manager.refs_as_dict(manager[14]))
         self.assertEqual({'a': 1, 'c': manager[7], 'b': 'string',
                           'd': manager[12]}, manager.refs_as_dict(manager[1]))
+
+    def test_expand_refs_as_list(self):
+        manager = loader.load(_instance_dump, show_prog=False)
+        self.assertEqual([2], manager.refs_as_list(manager[12]))



More information about the bazaar-commits mailing list