class TestBldr(unittest.TestCase): def init(self, filestring): self.f = StringIO(filestring) self.f.name = __file__ self.b = Bldr(self.f) def test_expansions(self): for cmd, expected in EXPANSIONS.items(): self.init(TEMPLATE.format(cmd)) result = ' '.join(self.b.cmds) self.assertEqual(result, expected) def test_contiguous(self): self.init(u""" # bldr: whatever # bldr: ok man % # not bldr # bldr: some other thing """) result = self.b.cmds expected = ['whatever', 'ok man ' + __file__] self.assertEqual(result, expected) def test_disable(self): self.init(u""" # bldr: debug # bldr: true """) self.assertTrue(self.b.debug) self.assertEqual(self.b.build(), -1) def test_returncode(self): self.init(u""" # bldr: false """) self.assertFalse(self.b.debug) self.assertEqual(self.b.build(), 1)
def init(self, filestring): self.f = StringIO(filestring) self.f.name = __file__ self.b = Bldr(self.f)