class TestTimestamp(unittest.TestCase): def setUp(self): self._context = JsBuildingContext() def test_timestamp(self): assert_equals(self._context.timestamp("20110603 12:00:00.042"), 0) assert_equals(self._context.timestamp("20110603 12:00:00.043"), 1) assert_equals(self._context.timestamp("20110603 12:00:00.000"), -42) assert_equals(self._context.timestamp("20110603 12:00:01.041"), 999) assert_equals(self._context.timestamp("20110604 12:00:00.042"), 24 * 60 * 60 * 1000) def test_none_timestamp(self): assert_equals(self._context.timestamp(None), None)
class TestTimestamp(unittest.TestCase): def setUp(self): self._context = JsBuildingContext() def test_timestamp(self): assert_equals(self._context.timestamp('20110603 12:00:00.042'), 0) assert_equals(self._context.timestamp('20110603 12:00:00.043'), 1) assert_equals(self._context.timestamp('20110603 12:00:00.000'), -42) assert_equals(self._context.timestamp('20110603 12:00:01.041'), 999) assert_equals(self._context.timestamp('20110604 12:00:00.042'), 24 * 60 * 60 * 1000) def test_none_timestamp(self): assert_equals(self._context.timestamp(None), None)
def test_prune_test_from_suite(self): suite = self.suite.suites[0] assert_equal(len(suite.suites), 0) assert_equal(len(suite.tests), 1) SuiteBuilder(JsBuildingContext(prune_input=True)).build(suite) assert_equal(len(suite.suites), 0) assert_equal(len(suite.tests), 0)
def test_prune_keyword(self): kw = self.suite.suites[0].tests[0].body[0] assert_equal(len(kw.body), 5) assert_equal(len(kw.messages), 3) KeywordBuilder(JsBuildingContext(prune_input=True)).build(kw) assert_equal(len(kw.body), 0) assert_equal(len(kw.messages), 0)
def test_message_linking(self): suite = self._get_suite_with_keywords() msg1 = suite.setup.body[0].body.create_message( 'Message 1', 'WARN', timestamp='20111204 22:04:03.210') msg2 = suite.tests.create().body.create_keyword().body.create_message( 'Message 2', 'ERROR', timestamp='20111204 22:04:04.210') context = JsBuildingContext(split_log=True) SuiteBuilder(context).build(suite) errors = ErrorsBuilder(context).build(ExecutionErrors([msg1, msg2])) assert_equal(remap(errors, context.strings), ((-1000, 3, 'Message 1', 's1-k1-k1'), (0, 4, 'Message 2', 's1-t1-k1'))) assert_equal(remap(context.link(msg1), context.strings), 's1-k1-k1') assert_equal(remap(context.link(msg2), context.strings), 's1-t1-k1') assert_true('*s1-k1-k1' in context.strings) assert_true('*s1-t1-k1' in context.strings) for res in context.split_results: assert_true('*s1-k1-k1' not in res[1]) assert_true('*s1-t1-k1' not in res[1])
class TestMinLogLevel(unittest.TestCase): def setUp(self): self._context = JsBuildingContext() def test_trace_is_identified_as_smallest_log_level(self): self._messages(LEVELS.keys()) assert_equals("TRACE", self._context.min_level) def test_debug_is_identified_when_no_trace(self): self._messages([l for l in LEVELS if l != "TRACE"]) assert_equals("DEBUG", self._context.min_level) def test_info_is_smallest_when_no_debug_or_trace(self): self._messages(["INFO", "WARN", "ERROR", "FAIL"]) assert_equals("INFO", self._context.min_level) def _messages(self, levels): levels = levels[:] random.shuffle(levels) for level in levels: self._context.message_level(level)
class TestMinLogLevel(unittest.TestCase): def setUp(self): self._context = JsBuildingContext() def test_trace_is_identified_as_smallest_log_level(self): self._messages(LEVELS.keys()) assert_equals('TRACE', self._context.min_level) def test_debug_is_identified_when_no_trace(self): self._messages([l for l in LEVELS if l != 'TRACE']) assert_equals('DEBUG', self._context.min_level) def test_info_is_smallest_when_no_debug_or_trace(self): self._messages(['INFO', 'WARN', 'ERROR', 'FAIL']) assert_equals('INFO', self._context.min_level) def _messages(self, levels): levels = levels[:] random.shuffle(levels) for level in levels: self._context.message_level(level)
def test_timestamps(self): suite = TestSuite(starttime='20111205 00:33:33.333') suite.setup.config(kwname='s1', starttime='20111205 00:33:33.334') suite.setup.body.create_message('Message', timestamp='20111205 00:33:33.343') suite.setup.body.create_message(level='DEBUG', timestamp='20111205 00:33:33.344') suite.tests.create(starttime='20111205 00:33:34.333') context = JsBuildingContext() model = SuiteBuilder(context).build(suite) self._verify_status(model[5], start=0) self._verify_status(model[-2][0][8], start=1) self._verify_mapped(model[-2][0][-1], context.strings, ((10, 2, 'Message'), (11, 1, ''))) self._verify_status(model[-3][0][4], start=1000)
def test_linking(self): self.errors.messages.create('Linkable', 'WARN', timestamp='20111206 14:33:00.001') context = JsBuildingContext() msg = TestSuite().tests.create().body.create_keyword().body.create_message( 'Linkable', 'WARN', timestamp='20111206 14:33:00.001' ) MessageBuilder(context).build(msg) model = ErrorsBuilder(context).build(self.errors) model = remap(model, context.strings) assert_equal(model, ((-1, 4, 'Error'), (41, 3, 'Warning'), (0, 3, 'Linkable', 's1-t1-k1')))
class TestMinLogLevel(unittest.TestCase): def setUp(self): self._context = JsBuildingContext() def test_trace_is_identified_as_smallest_log_level(self): self._messages(list(LEVELS)) assert_equals('TRACE', self._context.min_level) def test_debug_is_identified_when_no_trace(self): self._messages([l for l in LEVELS if l != 'TRACE']) assert_equals('DEBUG', self._context.min_level) def test_info_is_smallest_when_no_debug_or_trace(self): self._messages(['INFO', 'WARN', 'ERROR', 'FAIL']) assert_equals('INFO', self._context.min_level) def _messages(self, levels): levels = levels[:] random.shuffle(levels) for level in levels: self._context.message_level(level)
def test_no_pruning(self): SuiteBuilder(JsBuildingContext(prune_input=False)).build(self.suite) assert_equal(self.suite.setup.kwname, 's') assert_equal(self.suite.teardown.kwname, 't') assert_equal(self.suite.suites[0].setup.kwname, 's1') assert_equal(self.suite.suites[0].teardown.kwname, None) assert_equal(self.suite.suites[0].tests[0].setup.kwname, 'tcs') assert_equal(self.suite.suites[0].tests[0].teardown.kwname, 'tct') assert_equal(len(self.suite.suites[0].tests[0].body), 3) assert_equal(len(self.suite.suites[0].tests[0].body[0].body), 5) assert_equal(len(self.suite.suites[0].tests[0].body[0].messages), 3) assert_equal(self.suite.suites[0].tests[0].body[0].teardown.kwname, 'kt') assert_equal(len(self.suite.suites[1].tests[0].body), 1) assert_equal(len(self.suite.suites[1].tests[1].body), 2)
def _verify(self, strings, exp_ids, exp_strings, escape=True): exp_strings = tuple('*'+s for s in [''] + exp_strings) ctx = JsBuildingContext() results = [ctx.string(s, escape=escape) for s in strings] assert_equals(results, exp_ids) assert_equals(ctx.strings, exp_strings)
def _build_and_remap(self, suite, split_log=False): context = JsBuildingContext(split_log=split_log) model = remap(SuiteBuilder(context).build(suite), context.strings) return self._to_list(model), context
def _verify(self, strings, exp_ids, exp_strings): ctx = JsBuildingContext() results = [ctx.string(s) for s in strings] assert_equals(results, exp_ids) assert_equals(ctx.strings, exp_strings)
def _verify(self, strings, exp_ids, exp_strings, escape=True): exp_strings = tuple('*' + s for s in [''] + exp_strings) ctx = JsBuildingContext() results = [ctx.string(s, escape=escape) for s in strings] assert_equals(results, exp_ids) assert_equals(ctx.strings, exp_strings)
def test_prune_errors(self): errors = ExecutionErrors([Message(), Message()]) ErrorsBuilder(JsBuildingContext(prune_input=False)).build(errors) assert_equal(len(errors), 2) ErrorsBuilder(JsBuildingContext(prune_input=True)).build(errors) assert_equal(len(errors), 0)
def test_errors(self): context = JsBuildingContext() model = ErrorsBuilder(context).build(self.errors) model = remap(model, context.strings) assert_equal(model, ((0, 4, 'Error'), (42, 3, 'Warning')))
def _verify(self, strings, exp_ids, exp_strings): ctx = JsBuildingContext() results = [ctx.string(s) for s in strings] assert_equals(results, exp_ids) assert_equals(ctx.strings, exp_strings)
def test_prune_test(self): test = self.suite.suites[0].tests[0] assert_equal(len(test.body), 3) TestBuilder(JsBuildingContext(prune_input=True)).build(test) assert_equal(len(test.body), 0)
def setUp(self): self._context = JsBuildingContext()
def _build_and_verify(self, builder_class, item, *expected): self.context = JsBuildingContext(log_path=join(CURDIR, 'log.html')) model = builder_class(self.context).build(item) self._verify_mapped(model, self.context.strings, expected) return expected
def setUp(self): self._context = JsBuildingContext()
def _create_suite_model(self): self.context = JsBuildingContext() return SuiteBuilder(self.context).build(self._get_suite())
def _verify(self, strings, exp_ids, exp_strings): exp_strings = tuple("*" + s for s in [""] + exp_strings) ctx = JsBuildingContext() results = [ctx.string(s) for s in strings] assert_equals(results, exp_ids) assert_equals(ctx.strings, exp_strings)