Cleanup and enhance unit test.
Cleanup means merging two related suites and enhancment means
validating created output file. Related to PR
-import unittest
from os.path import join, dirname
+import os
+import unittest
+import tempfile
from robot.errors import DataError
from robot.result import ExecutionResult, Result
@@ -305,13 +307,13 @@ if PY3:
import pathlib
from os import devnull
- class TestBuildingFromPathlibPath(unittest.TestCase):
+ class TestUsingPathlibPath(unittest.TestCase):
def setUp(self):
self.result = ExecutionResult(pathlib.Path(join(dirname(__file__), 'golden.xml')))
- def test_suite(self):
- suite = self.result.suite
+ def test_suite_is_built(self, suite=None):
+ suite = suite or self.result.suite
assert_equal(suite.source, 'normal.html')
assert_equal(suite.name, 'Normal')
assert_equal(suite.doc, 'Normal test cases')
@@ -322,8 +324,8 @@ if PY3:
assert_equal(suite.statistics.passed, 1)
assert_equal(suite.statistics.failed, 0)
- def test_test_is_built(self):
- test = self.result.suite.tests[0]
+ def test_test_is_built(self, suite=None):
+ test = (suite or self.result.suite).tests[0]
assert_equal(test.name, 'First One')
assert_equal(test.doc, 'Test case documentation')
assert_equal(test.timeout, None)
@@ -333,16 +335,16 @@ if PY3:
assert_equal(test.starttime, '20111024 13:41:20.925')
assert_equal(test.endtime, '20111024 13:41:20.934')
- class TestSavingToPathlibPath(unittest.TestCase):
-
- def setUp(self):
- self.result = ExecutionResult(pathlib.Path(join(dirname(__file__), 'golden.xml')))
-
- def test_save_to_pathlib_path_supported(self):
+ def test_save(self):
+ temp = os.getenv('TEMPDIR', tempfile.gettempdir())
+ path = pathlib.Path(temp) / 'pathlib.xml'
+ self.result.save(path)
try:
- self.result.save(pathlib.Path(devnull))
- except AttributeError as e:
- fail('Saving ExecutionResult using pathlib.Path raises AttributeError: %s' % str(e))
+ result = ExecutionResult(path)
+ finally:
+ path.unlink()
+ self.test_suite_is_built(result.suite)
+ self.test_test_is_built(result.suite)
if __name__ == '__main__':
