26 Mar
2013
26 Mar
'13
2:21 p.m.
# HG changeset patch # User Tom Hayward tom@tomh.us # Date 1364246672 25200 # Node ID bf2e993f7f56a47780dbedc6ebc51213e524d511 # Parent a077b257ba116a08f5d9478d0b4219cd9dc2a640 bitwise: add "bit" type to for reading single-bit flags. #727
to for? six eight?
gen = self._types[dtype](self._data, self._offset)
if dtype == "bit":
if count % 8 != 0:
raise ValueError("bit array must be
divisible by 8.") +
class bitDE(bitDataElement):
_nbits = 1
_shift = 8 - i % 8
gen = bitDE(self._data, self._offset)
self._offset += int((i+1) % 8 == 0)
else:
gen = self._types[dtype](self._data,
self._offset)
self._offset += (gen.size() / 8)
The nesting is getting a bit deep here. Could you break this out into a helper like it is above to make it a bit easier to read?
+class TestBitType(BaseTest):
- def test_bit_array(self):
defn = "bit foo[24];"
obj = bitwise.parse(defn, "\x00\x80\x01")
for i, v in [(0, False), (8, True), (23, True)]:
self.assertEqual(bool(obj.foo[i]), v)
- def test_bit_array_fail(self):
self.assertRaises(ValueError, bitwise.parse, "bit foo[23];",
I was going to complain that this doesn't test setting the bit(s), but then I realized I never went back and did that myself :)
I assume you've verified that it works experimentally? I'll work on some write tests and can include bit tests there as well.
Thanks!
--
Dan Smith
www.danplanet.com
KK7DS