def attr_player_test(self): home = Element('home') home.player = 'you' home.player = 'him' try: home.player = 'hoge' self.assert_(False) except TypeError: return self.assert_(False)
def dtd_test(self): url = Element.dtd_url() try: obj = urllib.urlopen(url) except: self.assert_(False, 'failed to obtain dtd.') return uploaded = obj.read() assert uploaded uploaded = uploaded.split('\n') local = Element.make_dtd() assert local local= local.split('\n') for i, line in enumerate(local): self.assertEqual(uploaded[i], local[i]) self.assertEqual(uploaded[-1], '')
def setUp(self): self.board = Element('board') self.match = Element('match') self.action = Element('action') self.length = Element('length') self.crawford = Element('crawford') self.score = Element('score') self.position = Element('position') self.cubeholder = Element('cubeholder') self.field = Element('field') self.die = Element('die') self.cube = Element('cube') self.resign = Element('resign') self.home = Element('home') self.chequer = Element('chequer') self.bar = Element('bar') self.point = Element('point')
class ElementTest(unittest.TestCase): def setUp(self): self.board = Element('board') self.match = Element('match') self.action = Element('action') self.length = Element('length') self.crawford = Element('crawford') self.score = Element('score') self.position = Element('position') self.cubeholder = Element('cubeholder') self.field = Element('field') self.die = Element('die') self.cube = Element('cube') self.resign = Element('resign') self.home = Element('home') self.chequer = Element('chequer') self.bar = Element('bar') self.point = Element('point') def tearDown(self): pass def _append(self, name, oks): e = self.__dict__[name] if 'str' in oks: try: e.append('str') except: self.assert_(False) else: try: e.append('str') self.assert_(False) except: self.assert_(True) for key, item in self.__dict__.items(): if isinstance(item, BaseElement): if key in oks: try: e.append(item) except: self.assert_(False) else: try: e.append(item) self.assert_(False) except: self.assert_(True) def board_test(self): self._append('board', ['match', 'position']) def mag_test(self): self.board.width = 300 self.board.height = 200 self.board.set_mag([400, 300]) self.assertEqual(self.board.calc_mag([300, 200])[0], 400) self.assertNotEqual(self.board.calc_mag([300, 200])[1], 200) self.assertEqual(self.board.calc_mag([300, 200])[1], 266) self.assertEqual(self.board.calc_mag([150, 200])[0], 200) self.board.width = 300 self.board.height = 300 self.board.set_mag([400, 300]) self.assertEqual(self.board.calc_mag([300, 200])[0], 300) self.assertEqual(self.board.calc_mag([300, 200])[1], 200) def match_test(self): self._append('match', ['action', 'length', 'crawford', 'score']) def action_test(self): self._append('action', []) def length_test(self): self._append('length', []) def crawford_test(self): self._append('crawford', []) def score_test(self): self._append('score', []) def position_test(self): self._append('position', ['cubeholder', 'field', 'home', 'bar', 'point', 'top_frame', 'bottom_frame']) def cubeholder_test(self): self._append('cubeholder', ['cube']) def cube_test(self): self._append('cube', []) def field_test(self): self._append('field', ['cube', 'die', 'resign']) def home_test(self): self._append('home', ['cube', 'chequer']) def chequer_test(self): self._append('chequer', ['str']) def bar_test(self): self._append('bar', ['chequer']) def point_test(self): self._append('point', ['chequer'])
def attr_parity_test(self): point= Element('point') point.parity= 'even'