aboutsummaryrefslogtreecommitdiffstats
path: root/xtesting/tests
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2021-11-09 11:22:02 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2021-11-09 13:21:47 +0100
commit17739d718901a10f7ec0aaf9a6d53141294a347d (patch)
treea98e6d09a42016ceec90713adac681918a4a9c62 /xtesting/tests
parent92681911699428a87ea56c0263832b96a93da3da (diff)
Leverage latest pylint features
It adds encoding in all open call and leverage f-strings. Change-Id: I70ccd2bfcadae44929d5874f98fa3bf4ff644488 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'xtesting/tests')
-rw-r--r--xtesting/tests/unit/ci/test_run_tests.py2
-rw-r--r--xtesting/tests/unit/core/test_behaveframework.py12
-rw-r--r--xtesting/tests/unit/core/test_feature.py50
-rw-r--r--xtesting/tests/unit/core/test_robotframework.py12
-rw-r--r--xtesting/tests/unit/core/test_unit.py16
-rw-r--r--xtesting/tests/unit/utils/test_decorators.py6
6 files changed, 61 insertions, 37 deletions
diff --git a/xtesting/tests/unit/ci/test_run_tests.py b/xtesting/tests/unit/ci/test_run_tests.py
index b206a493..e2a2712c 100644
--- a/xtesting/tests/unit/ci/test_run_tests.py
+++ b/xtesting/tests/unit/ci/test_run_tests.py
@@ -100,7 +100,7 @@ class RunTestsTesting(unittest.TestCase):
mock_method.return_value.__iter__ = lambda self: iter(
self.readline, '')
self.runner.source_envfile(envfile)
- mock_method.assert_called_once_with(envfile, 'r')
+ mock_method.assert_called_once_with(envfile, 'r', encoding='utf-8')
self.assertEqual(os.environ[key], value)
def test_source_envfile(self):
diff --git a/xtesting/tests/unit/core/test_behaveframework.py b/xtesting/tests/unit/core/test_behaveframework.py
index 7cfcdec7..cd39f139 100644
--- a/xtesting/tests/unit/core/test_behaveframework.py
+++ b/xtesting/tests/unit/core/test_behaveframework.py
@@ -119,10 +119,10 @@ class RunTesting(unittest.TestCase):
html_file = os.path.join(self.test.res_dir, 'output.html')
args_list = [
'--junit',
- '--junit-directory={}'.format(self.test.res_dir),
- '--format=json', '--outfile={}'.format(self.test.json_file),
+ f'--junit-directory={self.test.res_dir}',
+ '--format=json', f'--outfile={self.test.json_file}',
'--format=behave_html_formatter:HTMLFormatter',
- '--outfile={}'.format(html_file),
+ f'--outfile={html_file}',
'--tags='+','.join(self.tags)]
args_list.append('foo')
args[0].assert_called_once_with(args_list)
@@ -152,10 +152,10 @@ class RunTesting(unittest.TestCase):
html_file = os.path.join(self.test.res_dir, 'output.html')
args_list = [
'--junit',
- '--junit-directory={}'.format(self.test.res_dir),
- '--format=json', '--outfile={}'.format(self.test.json_file),
+ f'--junit-directory={self.test.res_dir}',
+ '--format=json', f'--outfile={self.test.json_file}',
'--format=behave_html_formatter:HTMLFormatter',
- '--outfile={}'.format(html_file),
+ f'--outfile={html_file}',
'--tags='+','.join(self.tags)]
if console:
args_list += ['--format=pretty', '--outfile=-']
diff --git a/xtesting/tests/unit/core/test_feature.py b/xtesting/tests/unit/core/test_feature.py
index 9e5e109c..76ae2c1c 100644
--- a/xtesting/tests/unit/core/test_feature.py
+++ b/xtesting/tests/unit/core/test_feature.py
@@ -120,7 +120,7 @@ class BashFeatureTesting(FeatureTestingBase):
def test_run_ko1(self, *args):
with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run(testcase.TestCase.EX_RUN_ERROR)
- mopen.assert_called_once_with(self._output_file, "w")
+ mopen.assert_called_once_with(self._output_file, "w", encoding='utf-8')
args[0].assert_called_once_with(
self._cmd, shell=True, stderr=mock.ANY, stdout=mock.ANY)
args[1].assert_called_once_with(self.feature.res_dir)
@@ -136,8 +136,12 @@ class BashFeatureTesting(FeatureTestingBase):
args[0].configure_mock(**attrs)
with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run(testcase.TestCase.EX_RUN_ERROR)
- self.assertIn(mock.call(self._output_file, 'w'), mopen.mock_calls)
- self.assertIn(mock.call(self._output_file, 'r'), mopen.mock_calls)
+ self.assertIn(
+ mock.call(self._output_file, 'w', encoding='utf-8'),
+ mopen.mock_calls)
+ self.assertIn(
+ mock.call(self._output_file, 'r', encoding='utf-8'),
+ mopen.mock_calls)
args[0].assert_called_once_with(
self._cmd, shell=True, stderr=mock.ANY, stdout=mock.ANY)
args[1].assert_called_once_with(self.feature.res_dir)
@@ -159,8 +163,12 @@ class BashFeatureTesting(FeatureTestingBase):
args[1].configure_mock(**attrs)
with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run_max_duration(testcase.TestCase.EX_RUN_ERROR)
- self.assertIn(mock.call(self._output_file, 'w'), mopen.mock_calls)
- self.assertNotIn(mock.call(self._output_file, 'r'), mopen.mock_calls)
+ self.assertIn(
+ mock.call(self._output_file, 'w', encoding='utf-8'),
+ mopen.mock_calls)
+ self.assertNotIn(
+ mock.call(self._output_file, 'r', encoding='utf-8'),
+ mopen.mock_calls)
args[1].assert_called_once_with(
self._cmd, shell=True, stderr=mock.ANY, stdout=mock.ANY)
wait.assert_called_once_with(timeout=FeatureTestingBase._max_duration)
@@ -178,8 +186,12 @@ class BashFeatureTesting(FeatureTestingBase):
args[0].configure_mock(**attrs)
with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run(testcase.TestCase.EX_OK)
- self.assertIn(mock.call(self._output_file, 'w'), mopen.mock_calls)
- self.assertIn(mock.call(self._output_file, 'r'), mopen.mock_calls)
+ self.assertIn(
+ mock.call(self._output_file, 'w', encoding='utf-8'),
+ mopen.mock_calls)
+ self.assertIn(
+ mock.call(self._output_file, 'r', encoding='utf-8'),
+ mopen.mock_calls)
args[0].assert_called_once_with(
self._cmd, shell=True, stderr=mock.ANY, stdout=mock.ANY)
args[1].assert_called_once_with(self.feature.res_dir)
@@ -195,8 +207,12 @@ class BashFeatureTesting(FeatureTestingBase):
args[0].configure_mock(**attrs)
with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run_console(True, testcase.TestCase.EX_OK)
- self.assertIn(mock.call(self._output_file, 'w'), mopen.mock_calls)
- self.assertIn(mock.call(self._output_file, 'r'), mopen.mock_calls)
+ self.assertIn(
+ mock.call(self._output_file, 'w', encoding='utf-8'),
+ mopen.mock_calls)
+ self.assertIn(
+ mock.call(self._output_file, 'r', encoding='utf-8'),
+ mopen.mock_calls)
args[0].assert_called_once_with(
self._cmd, shell=True, stderr=mock.ANY, stdout=mock.ANY)
args[1].assert_called_once_with(self.feature.res_dir)
@@ -212,8 +228,12 @@ class BashFeatureTesting(FeatureTestingBase):
args[0].configure_mock(**attrs)
with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run_console(False, testcase.TestCase.EX_OK)
- self.assertIn(mock.call(self._output_file, 'w'), mopen.mock_calls)
- self.assertIn(mock.call(self._output_file, 'r'), mopen.mock_calls)
+ self.assertIn(
+ mock.call(self._output_file, 'w', encoding='utf-8'),
+ mopen.mock_calls)
+ self.assertIn(
+ mock.call(self._output_file, 'r', encoding='utf-8'),
+ mopen.mock_calls)
args[0].assert_called_once_with(
self._cmd, shell=True, stderr=mock.ANY, stdout=mock.ANY)
args[1].assert_called_once_with(self.feature.res_dir)
@@ -230,8 +250,12 @@ class BashFeatureTesting(FeatureTestingBase):
args[0].configure_mock(**attrs)
with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run_console(False, testcase.TestCase.EX_OK)
- self.assertIn(mock.call(self._output_file, 'w'), mopen.mock_calls)
- self.assertIn(mock.call(self._output_file, 'r'), mopen.mock_calls)
+ self.assertIn(
+ mock.call(self._output_file, 'w', encoding='utf-8'),
+ mopen.mock_calls)
+ self.assertIn(
+ mock.call(self._output_file, 'r', encoding='utf-8'),
+ mopen.mock_calls)
args[0].assert_called_once_with(
self._cmd, shell=True, stderr=mock.ANY, stdout=mock.ANY)
args[1].assert_called_once_with(self.feature.res_dir)
diff --git a/xtesting/tests/unit/core/test_robotframework.py b/xtesting/tests/unit/core/test_robotframework.py
index bc05f523..f36625e6 100644
--- a/xtesting/tests/unit/core/test_robotframework.py
+++ b/xtesting/tests/unit/core/test_robotframework.py
@@ -140,9 +140,9 @@ class GenerateReportTesting(unittest.TestCase):
args[0].assert_called_once_with(self.test.xml_file)
args[1].assert_called_once_with(args[0].return_value)
args[2].assert_called_once_with(
- report='{}/report.html'.format(self.test.res_dir),
- log='{}/log.html'.format(self.test.res_dir),
- xunit='{}/xunit.xml'.format(self.test.res_dir))
+ report=f'{self.test.res_dir}/report.html',
+ log=f'{self.test.res_dir}/log.html',
+ xunit=f'{self.test.res_dir}/xunit.xml')
@mock.patch('robot.reporting.resultwriter.ResultWriter.write_results',
return_value=0)
@@ -154,9 +154,9 @@ class GenerateReportTesting(unittest.TestCase):
args[0].assert_called_once_with(self.test.xml_file)
args[1].assert_called_once_with(args[0].return_value)
args[2].assert_called_once_with(
- report='{}/report.html'.format(self.test.res_dir),
- log='{}/log.html'.format(self.test.res_dir),
- xunit='{}/xunit.xml'.format(self.test.res_dir))
+ report=f'{self.test.res_dir}/report.html',
+ log=f'{self.test.res_dir}/log.html',
+ xunit=f'{self.test.res_dir}/xunit.xml')
class RunTesting(unittest.TestCase):
diff --git a/xtesting/tests/unit/core/test_unit.py b/xtesting/tests/unit/core/test_unit.py
index 9e5f1321..5cce83be 100644
--- a/xtesting/tests/unit/core/test_unit.py
+++ b/xtesting/tests/unit/core/test_unit.py
@@ -54,7 +54,7 @@ class SuiteTesting(unittest.TestCase):
['subunit2junitxml'], stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
mock_open.assert_called_once_with(
- '{}/results.xml'.format(self.psrunner.res_dir), 'w')
+ f'{self.psrunner.res_dir}/results.xml', 'w', encoding='utf-8')
@mock.patch('subprocess.Popen')
def test_generate_xunit_ok(self, *args):
@@ -69,7 +69,7 @@ class SuiteTesting(unittest.TestCase):
['subunit2junitxml'], stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
mock_open.assert_called_once_with(
- '{}/results.xml'.format(self.psrunner.res_dir), 'w')
+ f'{self.psrunner.res_dir}/results.xml', 'w', encoding='utf-8')
@mock.patch('subprocess.check_output', side_effect=Exception)
def test_generate_html_ko(self, *args):
@@ -78,7 +78,7 @@ class SuiteTesting(unittest.TestCase):
self.psrunner.generate_html(stream)
args[0].assert_called_once_with(
['subunit2html', stream,
- '{}/results.html'.format(self.psrunner.res_dir)])
+ f'{self.psrunner.res_dir}/results.html'])
@mock.patch('subprocess.check_output')
def test_generate_html_ok(self, *args):
@@ -86,7 +86,7 @@ class SuiteTesting(unittest.TestCase):
self.psrunner.generate_html(stream)
args[0].assert_called_once_with(
['subunit2html', stream,
- '{}/results.html'.format(self.psrunner.res_dir)])
+ f'{self.psrunner.res_dir}/results.html'])
@mock.patch('xtesting.core.unit.Suite.generate_html')
@mock.patch('xtesting.core.unit.Suite.generate_xunit')
@@ -98,14 +98,14 @@ class SuiteTesting(unittest.TestCase):
with mock.patch('builtins.open', mock.mock_open()) as m_open:
self.assertEqual(self.psrunner.run(), status)
m_open.assert_called_once_with(
- '{}/subunit_stream'.format(self.psrunner.res_dir), 'wb')
+ f'{self.psrunner.res_dir}/subunit_stream', 'wb')
self.assertEqual(self.psrunner.is_successful(), result)
args[0].assert_called_once_with(self.psrunner.suite)
args[1].assert_not_called()
args[2].assert_called_once_with(mock.ANY)
args[3].assert_called_once_with(mock.ANY)
args[4].assert_called_once_with(
- '{}/subunit_stream'.format(self.psrunner.res_dir))
+ f'{self.psrunner.res_dir}/subunit_stream')
@mock.patch('xtesting.core.unit.Suite.generate_html')
@mock.patch('xtesting.core.unit.Suite.generate_xunit')
@@ -117,14 +117,14 @@ class SuiteTesting(unittest.TestCase):
with mock.patch('builtins.open', mock.mock_open()) as m_open:
self.assertEqual(self.psrunner.run(name=name), status)
m_open.assert_called_once_with(
- '{}/subunit_stream'.format(self.psrunner.res_dir), 'wb')
+ f'{self.psrunner.res_dir}/subunit_stream', 'wb')
self.assertEqual(self.psrunner.is_successful(), result)
args[0].assert_called_once_with(self.psrunner.suite)
args[1].assert_called_once_with()
args[2].assert_called_once_with(mock.ANY)
args[3].assert_called_once_with(mock.ANY)
args[4].assert_called_once_with(
- '{}/subunit_stream'.format(self.psrunner.res_dir))
+ f'{self.psrunner.res_dir}/subunit_stream')
@mock.patch('xtesting.core.unit.Suite.generate_html')
@mock.patch('xtesting.core.unit.Suite.generate_xunit')
diff --git a/xtesting/tests/unit/utils/test_decorators.py b/xtesting/tests/unit/utils/test_decorators.py
index 2810df15..ae6ffa4b 100644
--- a/xtesting/tests/unit/utils/test_decorators.py
+++ b/xtesting/tests/unit/utils/test_decorators.py
@@ -24,8 +24,8 @@ from xtesting.utils import decorators
__author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
DIR = '/dev'
-FILE = '{}/null'.format(DIR)
-URL = 'file://{}'.format(FILE)
+FILE = f'{DIR}/null'
+URL = f'file://{FILE}'
class FakeTestCase(testcase.TestCase):
@@ -108,7 +108,7 @@ class DecoratorsTesting(unittest.TestCase):
create=True) as mock_open:
test = self._get_testcase()
self.assertEqual(test.push_to_db(), testcase.TestCase.EX_OK)
- mock_open.assert_called_once_with(FILE, 'a')
+ mock_open.assert_called_once_with(FILE, 'a', encoding='utf-8')
handle = mock_open()
call_args, _ = handle.write.call_args
self.assertIn('POST', call_args[0])