From d914e30fa26cf945a15f2041a3f20f283b35bc9c Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 3 Aug 2016 13:29:51 -0700 Subject: framework/backends/junit.py: Split _write into a separate class. This new class is attached as an attribute to the JUnitWriter class, in such a way that it has the same interface, and some attributes are moved to this new class since they're only needed there. This has the advantage of making the JUnitBackend class simpler, and makes the writing easier to test, it will also be used in a follow up patch to implement a different class that supports subtests. Signed-off-by: Dylan Baker Acked-by: Jose Fonseca (v1) Reviewed-by: Mark Janes Tested-by: Mark Janes --- unittests/framework/backends/test_junit.py | 47 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'unittests') diff --git a/unittests/framework/backends/test_junit.py b/unittests/framework/backends/test_junit.py index a8443db19..8f09dac16 100644 --- a/unittests/framework/backends/test_junit.py +++ b/unittests/framework/backends/test_junit.py @@ -189,31 +189,32 @@ class TestJUnitBackend(object): test.finalize() - class TestWriteTest(object): - """Tests for the write_test method.""" - def test_junit_replace(self, tmpdir): - """backends.junit.JUnitBackend.write_test: grouptools.SEPARATOR is - replaced with '.'. - """ - result = results.TestResult() - result.time.end = 1.2345 - result.result = 'pass' - result.out = 'this is stdout' - result.err = 'this is stderr' - result.command = 'foo' +class TestJUnitWriter(object): + """Tests for the JUnitWriter class.""" - test = backends.junit.JUnitBackend(six.text_type(tmpdir)) - test.initialize(shared.INITIAL_METADATA) - with test.write_test(grouptools.join('a', 'group', 'test1')) as t: - t(result) - test.finalize() - - test_value = etree.parse(six.text_type(tmpdir.join('results.xml'))) - test_value = test_value.getroot() - - assert test_value.find('.//testcase').attrib['classname'] == \ - 'piglit.a.group' + def test_junit_replace(self, tmpdir): + """backends.junit.JUnitBackend.write_test: grouptools.SEPARATOR is + replaced with '.'. + """ + result = results.TestResult() + result.time.end = 1.2345 + result.result = 'pass' + result.out = 'this is stdout' + result.err = 'this is stderr' + result.command = 'foo' + + test = backends.junit.JUnitBackend(six.text_type(tmpdir)) + test.initialize(shared.INITIAL_METADATA) + with test.write_test(grouptools.join('a', 'group', 'test1')) as t: + t(result) + test.finalize() + + test_value = etree.parse(six.text_type(tmpdir.join('results.xml'))) + test_value = test_value.getroot() + + assert test_value.find('.//testcase').attrib['classname'] == \ + 'piglit.a.group' class TestValid(object): @pytest.fixture -- cgit v1.2.3