diff options
Diffstat (limited to 'xtesting/tests/unit/core')
-rw-r--r-- | xtesting/tests/unit/core/test_feature.py | 24 | ||||
-rw-r--r-- | xtesting/tests/unit/core/test_unit.py | 14 |
2 files changed, 22 insertions, 16 deletions
diff --git a/xtesting/tests/unit/core/test_feature.py b/xtesting/tests/unit/core/test_feature.py index 76f5d85a..9e5e109c 100644 --- a/xtesting/tests/unit/core/test_feature.py +++ b/xtesting/tests/unit/core/test_feature.py @@ -88,7 +88,6 @@ class FeatureTesting(FeatureTestingBase): project_name=self._project_name, case_name=self._case_name) def test_run_exc(self): - # pylint: disable=bad-continuation with mock.patch.object( self.feature, 'execute', side_effect=Exception) as mock_method: @@ -132,7 +131,8 @@ class BashFeatureTesting(FeatureTestingBase): stream = BytesIO() stream.write(b"foo") stream.seek(0) - attrs = {'return_value.stdout': stream, 'return_value.returncode': 1} + attrs = {'return_value.__enter__.return_value.stdout': stream, + 'return_value.__enter__.return_value.returncode': 1} args[0].configure_mock(**attrs) with mock.patch('builtins.open', mock.mock_open()) as mopen: self._test_run(testcase.TestCase.EX_RUN_ERROR) @@ -152,10 +152,10 @@ class BashFeatureTesting(FeatureTestingBase): cmd=FeatureTestingBase._cmd, timeout=FeatureTestingBase._max_duration)) kill = mock.MagicMock() - attrs = {'return_value.wait': wait, - 'return_value.kill': kill, - 'return_value.stdout': stream, - 'return_value.returncode': 0} + attrs = {'return_value.__enter__.return_value.wait': wait, + 'return_value.__enter__.return_value.kill': kill, + 'return_value.__enter__.return_value.stdout': stream, + 'return_value.__enter__.return_value.returncode': 0} 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) @@ -173,7 +173,8 @@ class BashFeatureTesting(FeatureTestingBase): stream = BytesIO() stream.write(b"foo") stream.seek(0) - attrs = {'return_value.stdout': stream, 'return_value.returncode': 0} + attrs = {'return_value.__enter__.return_value.stdout': stream, + 'return_value.__enter__.return_value.returncode': 0} args[0].configure_mock(**attrs) with mock.patch('builtins.open', mock.mock_open()) as mopen: self._test_run(testcase.TestCase.EX_OK) @@ -189,7 +190,8 @@ class BashFeatureTesting(FeatureTestingBase): stream = BytesIO() stream.write(b"foo") stream.seek(0) - attrs = {'return_value.stdout': stream, 'return_value.returncode': 0} + attrs = {'return_value.__enter__.return_value.stdout': stream, + 'return_value.__enter__.return_value.returncode': 0} args[0].configure_mock(**attrs) with mock.patch('builtins.open', mock.mock_open()) as mopen: self._test_run_console(True, testcase.TestCase.EX_OK) @@ -205,7 +207,8 @@ class BashFeatureTesting(FeatureTestingBase): stream = BytesIO() stream.write(b"foo") stream.seek(0) - attrs = {'return_value.stdout': stream, 'return_value.returncode': 0} + attrs = {'return_value.__enter__.return_value.stdout': stream, + 'return_value.__enter__.return_value.returncode': 0} args[0].configure_mock(**attrs) with mock.patch('builtins.open', mock.mock_open()) as mopen: self._test_run_console(False, testcase.TestCase.EX_OK) @@ -222,7 +225,8 @@ class BashFeatureTesting(FeatureTestingBase): stream = BytesIO() stream.write(b"foo") stream.seek(0) - attrs = {'return_value.stdout': stream, 'return_value.returncode': 0} + attrs = {'return_value.__enter__.return_value.stdout': stream, + 'return_value.__enter__.return_value.returncode': 0} args[0].configure_mock(**attrs) with mock.patch('builtins.open', mock.mock_open()) as mopen: self._test_run_console(False, testcase.TestCase.EX_OK) diff --git a/xtesting/tests/unit/core/test_unit.py b/xtesting/tests/unit/core/test_unit.py index 86577713..9e5f1321 100644 --- a/xtesting/tests/unit/core/test_unit.py +++ b/xtesting/tests/unit/core/test_unit.py @@ -32,10 +32,11 @@ class SuiteTesting(unittest.TestCase): args[0].assert_called_once_with( ['subunit-stats'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) - @mock.patch('subprocess.Popen', - return_value=mock.Mock( - communicate=mock.Mock(return_value=(b"foo", b"bar")))) + @mock.patch('subprocess.Popen') def test_generate_stats_ok(self, *args): + attrs = {'return_value.__enter__.return_value': mock.Mock( + communicate=mock.Mock(return_value=(b"foo", b"bar")))} + args[0].configure_mock(**attrs) stream = io.StringIO() self.psrunner.generate_stats(stream) args[0].assert_called_once_with( @@ -55,10 +56,11 @@ class SuiteTesting(unittest.TestCase): mock_open.assert_called_once_with( '{}/results.xml'.format(self.psrunner.res_dir), 'w') - @mock.patch('subprocess.Popen', - return_value=mock.Mock( - communicate=mock.Mock(return_value=(b"foo", b"bar")))) + @mock.patch('subprocess.Popen') def test_generate_xunit_ok(self, *args): + attrs = {'return_value.__enter__.return_value': mock.Mock( + communicate=mock.Mock(return_value=(b"foo", b"bar")))} + args[0].configure_mock(**attrs) stream = io.BytesIO() with mock.patch('builtins.open', mock.mock_open()) as mock_open: |