def test_artifacts_merged(self): test_names = [ 'foo_test.FooTest.foobar' ] result_set = json_results.ResultSet() ar = FakeArtifacts() ar.artifacts = {'artifact_name': ['a/b/c.txt']} result_set.add(json_results.Result( 'foo_test.FooTest.foobar', json_results.ResultType.Failure, 0, 0.2, 0, artifacts=ar.artifacts)) ar2 = FakeArtifacts() ar2.artifacts = {'artifact_name': ['d/e/f.txt']} result_set.add(json_results.Result( 'foo_test.FooTest.foobar', json_results.ResultType.Failure, 0, 0.2, 0, artifacts=ar2.artifacts)) full_results = json_results.make_full_results( {'foo': 'bar'}, 0, test_names, result_set) tests = full_results['tests']['foo_test']['FooTest'] self.assertIn('artifacts', tests['foobar']) # Order is not guaranteed for the list of paths, so don't use # assertEqual if there are multiple entries artifacts = tests['foobar']['artifacts'] self.assertIn('artifact_name', artifacts) self.assertEqual(len(artifacts['artifact_name']), 2) self.assertIn('a/b/c.txt', artifacts['artifact_name']) self.assertIn('d/e/f.txt', artifacts['artifact_name'])
def test_basic(self): test_names = ['foo_test.FooTest.test_fail', 'foo_test.FooTest.test_pass', 'foo_test.FooTest.test_skip'] result_set = json_results.ResultSet() result_set.add( json_results.Result('foo_test.FooTest.test_fail', json_results.ResultType.Failure, 0, 0.1, 0, unexpected=True)) result_set.add(json_results.Result('foo_test.FooTest.test_pass', json_results.ResultType.Pass, 0, 0.2, 0)) result_set.add(json_results.Result('foo_test.FooTest.test_skip', json_results.ResultType.Skip, 0, 0.3, 0, expected=[json_results.ResultType.Skip], unexpected=False)) full_results = json_results.make_full_results( {'foo': 'bar'}, 0, test_names, result_set) expected_full_results = { 'foo': 'bar', 'metadata': { 'foo': 'bar'}, 'interrupted': False, 'num_failures_by_type': { 'FAIL': 1, 'PASS': 1, 'SKIP': 1}, 'num_regressions': 1, 'path_delimiter': '.', 'seconds_since_epoch': 0, 'tests': { 'foo_test': { 'FooTest': { 'test_fail': { 'expected': 'PASS', 'actual': 'FAIL', 'times': [0.1], 'is_unexpected': True, 'is_regression': True, }, 'test_pass': { 'expected': 'PASS', 'actual': 'PASS', 'times': [0.2], }, 'test_skip': { 'expected': 'SKIP', 'actual': 'SKIP', 'times': [0.3], }}}}, 'version': 3} self.assertEqual(full_results, expected_full_results)
def test_unknown_result(self): test_names = ['foo_test.FooTest.test_unknown_result'] result_set = json_results.ResultSet() result_set.add( json_results.Result('foo_test.FooTest.test_unknown_result', 'UNKNOWN', 0, 0.2, 0)) with self.assertRaises(ValueError) as ctx: full_results = json_results.make_full_results({'foo': 'bar'}, 0, test_names, result_set) self.assertIn('UNKNOWN', str(ctx.exception))
def CreateResult(input_dict): """Creates a ResultSet with Results. Args: input_dict: A dict describing the result to create. Returns: A Result filled with the information from |input_dict| """ return json_results.Result(name=input_dict['name'], actual=input_dict['actual'], started=True, took=1, worker=None, expected=input_dict.get('expected'), out=input_dict.get('out', 'stdout'), err=input_dict.get('err', 'stderr'), artifacts=input_dict.get('artifacts'))
def test_artifacts_and_types_added(self): ar = FakeArtifacts() ar.artifacts = {'artifact_name': ['a/b/c.txt']} test_names = [ 'foo_test.FooTest.foobar' ] result_set = json_results.ResultSet() result_set.add(json_results.Result( 'foo_test.FooTest.foobar', json_results.ResultType.Pass, 0, 0.2, 0, artifacts=ar.artifacts)) full_results = json_results.make_full_results( {'foo': 'bar'}, 0, test_names, result_set) tests = full_results['tests']['foo_test']['FooTest'] self.assertIn('artifacts', tests['foobar']) self.assertEqual(tests['foobar']['artifacts'], {'artifact_name': ['a/b/c.txt']})