def test_correct_number_of_fields(self): b = Builder() b.set_template(TMPL_TWO_FIELDS) b.prepare() self.assertEqual(2, b.count())
def test_get_raw(self): b = Builder() b.set_template("foo[1] = 1, foe[2] = 2") b.prepare() self.assertTrue(b.is_correct()) target = "\x01\x00\x02" self.assertEqual(target, b.get_raw())
def test_correct_sizes_of_fields(self): b = Builder() b.set_template(TMPL_TWO_FIELDS) b.prepare() fields = b.get_fields() self.assertEqual(1, fields["foo"].size) self.assertEqual(2, fields["foe"].size)
def test_correct_names_of_fields(self): b = Builder() b.set_template(TMPL_TWO_FIELDS) b.prepare() fields = b.get_fields() self.assertEqual(2, len(fields)) self.assertTrue("foo" in fields) self.assertTrue("foe" in fields)
def test_is_correct(self): b = Builder() b.set_template(TMPL_TWO_FIELDS) b.prepare() self.assertFalse(b.is_correct()) b = Builder() b.set_template("foo[1] = 128") b.prepare() self.assertTrue(b.is_correct()) b = Builder() b.set_template("foo[1] = 0, foe[2], bar[1] = 2") b.prepare() self.assertFalse(b.is_correct()) b.fields["foe"].value = 3 self.assertTrue(b.is_correct())