Rev 5389: Change the _test names to _get and _py so that it doesn't provoke bad smells :) in http://bazaar.launchpad.net/~jameinel/bzr/2.3-btree-chk-leaf

John Arbash Meinel john at arbash-meinel.com
Mon Aug 23 18:51:33 BST 2010


At http://bazaar.launchpad.net/~jameinel/bzr/2.3-btree-chk-leaf

------------------------------------------------------------
revno: 5389
revision-id: john at arbash-meinel.com-20100823175117-hr3b7p8gkw4ap8bb
parent: john at arbash-meinel.com-20100806153824-inx9xjyuzneci1qw
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.3-btree-chk-leaf
timestamp: Mon 2010-08-23 12:51:17 -0500
message:
  Change the _test names to _get and _py so that it doesn't provoke bad smells :)
-------------- next part --------------
=== modified file 'bzrlib/_btree_serializer_pyx.pyx'
--- a/bzrlib/_btree_serializer_pyx.pyx	2010-08-05 22:05:49 +0000
+++ b/bzrlib/_btree_serializer_pyx.pyx	2010-08-23 17:51:17 +0000
@@ -379,7 +379,7 @@
     return 1
 
 
-def _test_unhexlify(as_hex):
+def _py_unhexlify(as_hex):
     """For the test infrastructure, just thunks to _unhexlify_sha1"""
     if len(as_hex) != 40 or not PyString_CheckExact(as_hex):
         raise ValueError('not a 40-byte hex digest')
@@ -402,7 +402,7 @@
         j += 1
 
 
-def _test_hexlify(as_bin):
+def _py_hexlify(as_bin):
     """For test infrastructure, thunk to _hexlify_sha1"""
     if len(as_bin) != 20 or not PyString_CheckExact(as_bin):
         raise ValueError('not a 20-byte binary digest')
@@ -439,7 +439,7 @@
     return 1
 
 
-def _test_key_to_sha1(key):
+def _py_key_to_sha1(key):
     """Map a key to a simple sha1 string.
 
     This is a testing thunk to the C function.
@@ -475,7 +475,7 @@
     return key
 
 
-def _test_sha1_to_key(sha1_bin):
+def _py_sha1_to_key(sha1_bin):
     """Test thunk to check the sha1 mapping."""
     if not PyString_CheckExact(sha1_bin) or PyString_GET_SIZE(sha1_bin) != 20:
         raise ValueError('sha1_bin must be a str of exactly 20 bytes')
@@ -765,7 +765,7 @@
         this_offset = (as_uint >> self.common_shift) & 0xFF
         return this_offset
 
-    def test_offset_for_sha1(self, sha1):
+    def _get_offset_for_sha1(self, sha1):
         return self._offset_for_sha1(PyString_AS_STRING(sha1))
 
     cdef _compute_common(self):
@@ -814,13 +814,12 @@
             self.offsets[offset] = max_offset
             offset += 1
 
-    property _test_offsets:
-        def __get__(self):
-            cdef int i
-            result = []
-            for i from 0 <= i < 257:
-                PyList_Append(result, self.offsets[i])
-            return result
+    def _get_offsets(self):
+        cdef int i
+        result = []
+        for i from 0 <= i < 257:
+            PyList_Append(result, self.offsets[i])
+        return result
 
 
 def _parse_into_chk(bytes, key_length, ref_list_length):

=== modified file 'bzrlib/tests/test__btree_serializer.py'
--- a/bzrlib/tests/test__btree_serializer.py	2010-08-06 15:38:24 +0000
+++ b/bzrlib/tests/test__btree_serializer.py	2010-08-23 17:51:17 +0000
@@ -38,23 +38,23 @@
 
     def assertHexlify(self, as_binary):
         self.assertEqual(binascii.hexlify(as_binary),
-                         self.module._test_hexlify(as_binary))
+                         self.module._py_hexlify(as_binary))
 
     def assertUnhexlify(self, as_hex):
         ba_unhex = binascii.unhexlify(as_hex)
-        mod_unhex = self.module._test_unhexlify(as_hex)
+        mod_unhex = self.module._py_unhexlify(as_hex)
         if ba_unhex != mod_unhex:
             if mod_unhex is None:
                 mod_hex = '<None>'
             else:
                 mod_hex = binascii.hexlify(mod_unhex)
-            self.fail('_test_unhexlify returned a different answer'
+            self.fail('_py_unhexlify returned a different answer'
                       ' from binascii:\n    %s\n != %s'
                       % (binascii.hexlify(ba_unhex), mod_hex))
 
     def assertFailUnhexlify(self, as_hex):
         # Invalid hex content
-        self.assertIs(None, self.module._test_unhexlify(as_hex))
+        self.assertIs(None, self.module._py_unhexlify(as_hex))
 
     def test_to_hex(self):
         raw_bytes = ''.join(map(chr, range(256)))
@@ -86,7 +86,7 @@
             expected_bin = None
         else:
             expected_bin = binascii.unhexlify(expected)
-        actual_sha1 = self.module._test_key_to_sha1(key)
+        actual_sha1 = self.module._py_key_to_sha1(key)
         if expected_bin != actual_sha1:
             actual_hex_sha1 = None
             if actual_sha1 is not None:
@@ -121,7 +121,7 @@
 
     def assertSha1ToKey(self, hex_sha1):
         bin_sha1 = binascii.unhexlify(hex_sha1)
-        key = self.module._test_sha1_to_key(bin_sha1)
+        key = self.module._py_sha1_to_key(bin_sha1)
         self.assertEqual(('sha1:' + hex_sha1,), key)
 
     def test_simple(self):
@@ -229,7 +229,7 @@
         # The interesting byte for each key is
         # (defined as the 8-bits that come after the common prefix)
         lst = [1, 13, 28, 180, 190, 193, 210, 239]
-        offsets = leaf._test_offsets
+        offsets = leaf._get_offsets()
         self.assertEqual([bisect.bisect_left(lst, x) for x in range(0, 257)],
                          offsets)
         for idx, val in enumerate(lst):
@@ -241,7 +241,7 @@
         # there is no common prefix, though there are some common bits
         leaf = self.module._parse_into_chk(_multi_key_same_offset, 1, 0)
         self.assertEqual(24, leaf.common_shift)
-        offsets = leaf._test_offsets
+        offsets = leaf._get_offsets()
         # The interesting byte is just the first 8-bits of the key
         lst = [8, 200, 205, 205, 205, 205, 206, 206]
         self.assertEqual([bisect.bisect_left(lst, x) for x in range(0, 257)],
@@ -257,7 +257,7 @@
         leaf = self.module._parse_into_chk(_common_32_bits, 1, 0)
         self.assertEqual(0, leaf.common_shift)
         lst = [0x78] * 8
-        offsets = leaf._test_offsets
+        offsets = leaf._get_offsets()
         self.assertEqual([bisect.bisect_left(lst, x) for x in range(0, 257)],
                          offsets)
         for val in lst:
@@ -277,7 +277,7 @@
         bytes = ''.join(lines)
         leaf = self.module._parse_into_chk(bytes, 1, 0)
         self.assertEqual(24-7, leaf.common_shift)
-        offsets = leaf._test_offsets
+        offsets = leaf._get_offsets()
         # This is the interesting bits for each entry
         lst = [x // 2 for x in range(500)]
         expected_offsets = [x * 2 for x in range(128)] + [255]*129



More information about the bazaar-commits mailing list