robotframework===3.1.1
bandit===1.1.0
behave===1.2.6
-behave-html-formatter===0.9.4;python_version>='3.5'
-pylint===1.9.5;python_version=='2.7'
-pylint===2.4.4;python_version=='3.9'
+behave-html-formatter===0.9.4
+pylint===2.9.6
flake8===3.9.2
nose===1.3.7
ansible-lint===4.3.7
@staticmethod
def get_dict_by_test(testname):
- # pylint: disable=bad-continuation,missing-docstring
+ # pylint: disable=missing-docstring
with open(pkg_resources.resource_filename(
'xtesting', 'ci/testcases.yaml')) as tyaml:
testcases_yaml = yaml.safe_load(tyaml)
return tier_names
def get_tier(self, tier_name):
- for i in range(0, len(self.tier_objects)):
+ for i, _ in enumerate(self.tier_objects):
if self.tier_objects[i].get_name() == tier_name:
return self.tier_objects[i]
return None
def get_tier_name(self, test_name):
- for i in range(0, len(self.tier_objects)):
+ for i, _ in enumerate(self.tier_objects):
if self.tier_objects[i].is_test(test_name):
return self.tier_objects[i].name
return None
def get_test(self, test_name):
- for i in range(0, len(self.tier_objects)):
+ for i, _ in enumerate(self.tier_objects):
if self.tier_objects[i].is_test(test_name):
return self.tier_objects[i].get_test(test_name)
return None
def get_tests(self, tier_name):
- for i in range(0, len(self.tier_objects)):
+ for i, _ in enumerate(self.tier_objects):
if self.tier_objects[i].get_name() == tier_name:
return self.tier_objects[i].get_tests()
return None
def __str__(self):
output = ""
- for i in range(0, len(self.tier_objects)):
+ for i, _ in enumerate(self.tier_objects):
output += str(self.tier_objects[i]) + "\n"
return output
os.makedirs(self.res_dir)
with open(self.result_file, 'w') as f_stdout:
self.__logger.info("Calling %s", cmd)
- process = subprocess.Popen(
- cmd, shell=True, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
- for line in iter(process.stdout.readline, b''):
- if console:
- sys.stdout.write(line.decode("utf-8"))
- f_stdout.write(line.decode("utf-8"))
- try:
- process.wait(timeout=max_duration)
- except subprocess.TimeoutExpired:
- process.kill()
- self.__logger.info(
- "Killing process after %d second(s).", max_duration)
- return -2
+ with subprocess.Popen(
+ cmd, shell=True, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT) as process:
+ for line in iter(process.stdout.readline, b''):
+ if console:
+ sys.stdout.write(line.decode("utf-8"))
+ f_stdout.write(line.decode("utf-8"))
+ try:
+ process.wait(timeout=max_duration)
+ except subprocess.TimeoutExpired:
+ process.kill()
+ self.__logger.info(
+ "Killing process after %d second(s).",
+ max_duration)
+ return -2
with open(self.result_file, 'r') as f_stdin:
self.__logger.debug("$ %s\n%s", cmd, f_stdin.read().rstrip())
return process.returncode
Exception
"""
stream.seek(0)
- stats = subprocess.Popen(
- ['subunit-stats'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- output, _ = stats.communicate(stream.read())
- cls.__logger.info("\n\n%s", output.decode("utf-8"))
+ with subprocess.Popen(
+ ['subunit-stats'], stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE) as stats:
+ output, _ = stats.communicate(stream.read())
+ cls.__logger.info("\n\n%s", output.decode("utf-8"))
def generate_xunit(self, stream):
"""Generate junit report from subunit stream
"""
stream.seek(0)
with open("{}/results.xml".format(self.res_dir), "w") as xml:
- stats = subprocess.Popen(
- ['subunit2junitxml'], stdin=subprocess.PIPE,
- stdout=subprocess.PIPE)
- output, _ = stats.communicate(stream.read())
- xml.write(output.decode("utf-8"))
+ with subprocess.Popen(
+ ['subunit2junitxml'], stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE) as stats:
+ output, _ = stats.communicate(stream.read())
+ xml.write(output.decode("utf-8"))
def generate_html(self, stream):
"""Generate html report from subunit stream
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:
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)
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)
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)
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)
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)
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)
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(
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: