class TestOptions(unittest.TestCase): def setUp(self): self.options = Options() def tearDown(self): self.options.clear() def test_item(self): """It should be possible to access items in the options instance""" option = Options(foo="bar", test=42) self.assertEqual(option["foo"], "bar") self.assertEqual(option["test"], 42) def test_invalid_item(self): """Options should raise KeyError if accessing an invalid item""" option = Options(foo="bar", test=42) self.assertRaises(KeyError, option.__getitem__, "laba") def test_borg(self): """All options instances should share state""" option = Options(foo="bar", test=42) option2 = Options() self.assertEqual(option["test"], option2["test"]) def test_length(self): """It should be possible to get the length of a group""" option = Options(foo="bar", test=42) self.assertEqual(len(option), 2) def test_iteration(self): """It should be possible to iterate over the group""" option = Options(foo="bar", test=42) for _ in option: pass
def setUp(self): self.options = Options()