def test_add_text(self): c = ReviewConfiguration() c.add_text("\n# Some comment...\n") cl = tuple(c) self.assertEqual(len(cl), 0) self.assertEqual(str(c).split("\n"), ["", "# Some comment...", ""])
def test_config_rows_appear_the_same_for_loaded_multi_line_review(self): c = ReviewConfiguration() rows = [ "123 -i hal/* \\", " -i platform/* \\", " -i manuals/*", "new -x hal/*" ] c.load(rows) self.assertEqual(str(c).split("\n"), rows)
def test_load(self): c = ReviewConfiguration() c.load(["123 -i hal/*", "new -x hal/*"]) cl = tuple(c) self.assertEqual(cl[0].review_id, "123") self.assertEqual(cl[0].filter_args, "-i hal/*") self.assertTrue(cl[1].review_id is None) self.assertEqual(cl[1].filter_args, "-x hal/*") self.assertEqual(str(c).split("\n"), ["123 -i hal/*", "new -x hal/*"]) self.assertEqual(len(cl), 2)
def test_load_with_review_spanning_multiple_lines(self): c = ReviewConfiguration() c.load([ "123 -i hal/* \\", " -i platform/* \\", " -i manuals/*", "new -x hal/*" ]) cl = tuple(c) self.assertEqual(len(cl), 2) self.assertEqual(cl[0].review_id, "123") self.assertEqual(cl[0].filter_args, "-i hal/* -i platform/* -i manuals/*") self.assertTrue(cl[1].review_id is None) self.assertEqual(cl[1].filter_args, "-x hal/*")
def test_config_rows_appear_in_same_order_as_added(self): c = ReviewConfiguration() c.add_review("123", "-i hal/*") c.add_text("# comment ...") c.add_review("456", "-i platform/*") self.assertEqual( str(c).split("\n"), ["123 -i hal/*", "# comment ...", "456 -i platform/*"])
def test_error_for_loading_invalid_review_row(self): c = ReviewConfiguration() with self.assertRaisesRegexp(ExecutionError, "invalid config format: row 1"): c.load(["invalid -i hal/*"]) with self.assertRaisesRegexp(ExecutionError, "invalid config format: row 4"): c.load([ "123 -i hal/* \\", " -i platform/* \\", " -i manuals/*", "invalid -x hal/*" ])
def test_config_rows_can_update_without_change_of_order(self): c = ReviewConfiguration() c.add_review("123", "-i hal/*") c.add_text("# comment ...") self.assertEqual(str(c).split("\n"), ["123 -i hal/*", "# comment ..."]) cl = tuple(c) cl[0].review_id = "567" self.assertEqual(str(c).split("\n"), ["567 -i hal/*", "# comment ..."])
def test_config_rows_appear_in_same_order_as_loaded(self): c = ReviewConfiguration() rows = ["123 -i hal/*", "# comment", "456 -i platform/*"] c.load(rows) self.assertEqual(str(c).split("\n"), rows)
def test_uncommitted_option_default_value(self): c = ReviewConfiguration() self.assertEqual(c.get_option("uncommitted"), "false")
def test_load_with_empty_lines(self): c = ReviewConfiguration() c.load(["", "123 -i hal/*"]) self.assertEqual(len(tuple(c)), 1)
def test_load_with_comments(self): c = ReviewConfiguration() c.load(["# some comment...", "123 -i hal/*"]) self.assertEqual(len(tuple(c)), 1)
def test_uncommitted_selected(self): c = ReviewConfiguration() c.set_option("uncommitted", "true") self.assertEqual(c.get_option("uncommitted"), "true")
def test_error_for_adding_review_with_invalid_id(self): c = ReviewConfiguration() with self.assertRaisesRegexp(ExecutionError, "invalid review_id"): c.add_review("invalid", "-i hal/*")
def test_initial_state(self): c = ReviewConfiguration() self.assertEqual(str(c), "") self.assertEqual(len(tuple(c)), 0)
def test_deprecated_option_item_is_remove_from_output(self): c = ReviewConfiguration() c.add_review("123", "-i hal/*") c.set_option("uncommitted", "true") self.assertEqual(str(c).split("\n"), ["123 -i hal/*"])
def test_load_option_uncommitted(self): c = ReviewConfiguration() c.load([]) self.assertEqual(c.get_option("uncommitted"), "false") c = ReviewConfiguration() c.load(["@uncommitted = false"]) self.assertEqual(c.get_option("uncommitted"), "false") c = ReviewConfiguration() c.load(["@uncommitted = true"]) self.assertEqual(c.get_option("uncommitted"), "true") c = ReviewConfiguration() c.load(["@uncommitted=true"]) self.assertEqual(c.get_option("uncommitted"), "true")
def test_error_for_add_invalid_text(self): c = ReviewConfiguration() with self.assertRaisesRegexp(ExecutionError, "invalid text"): c.add_text("\nLine not prefixed with #...\n")
def test_error_for_getting_invalid_option(self): c = ReviewConfiguration() with self.assertRaisesRegexp(ExecutionError, "invalid config option"): c.get_option("does_not_exist")
def test_error_for_loading_invalid_option_row(self): c = ReviewConfiguration() with self.assertRaisesRegexp(ExecutionError, "invalid config format"): c.load(["@uncommitted"])
def test_error_for_invalid_option_value(self): c = ReviewConfiguration() with self.assertRaisesRegexp(ExecutionError, "invalid option value"): c.load(["@uncommitted = 1"])
def test_error_for_loading_invalid_option(self): c = ReviewConfiguration() with self.assertRaisesRegexp(ExecutionError, "invalid config option"): c.load(["@does_not_exist = true"])