Skip to content

Commit

Permalink
fix tests that fail in the pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Tattoo committed Oct 19, 2023
1 parent 6c4a267 commit 5bf9f29
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 18 deletions.
1 change: 0 additions & 1 deletion .github/workflows/run-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ runs:
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
cache: 'pip'
- name: Install dependencies
shell: ${{ inputs.terminal }}
run: |
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ mock>=2.0.0
invoke>=1.1.1
coverage>=5.1
testfixtures>=6.14.1 # needed for large dict comparisons to make sense of them
green>=3.1.3 # unit test runner
pytest>=7.4.2
pytest-cov>=4.1.0
docutils>=0.16 # needed to generate library documentation with libdoc
Pygments>=2.6.1 # this one too
twine>=3.1.1 # needed for releasing to pypi
Expand Down
10 changes: 5 additions & 5 deletions src/oxygen/oxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ def handlers(self):
return self._handlers

def _register_handlers(self):
for tool_name, config in self.config.items():
for tool_name, handler_config in self.config.items():
try:
handler_class = getattr(__import__(tool_name,
fromlist=[config['handler']]),
config['handler'])
handler_class = getattr(
__import__(tool_name, fromlist=[handler_config['handler']]),
handler_config['handler'])
except ModuleNotFoundError as e:
raise InvalidConfigurationException(e)
handler = handler_class(config)
handler = handler_class(handler_config)
self._handlers[tool_name] = handler


Expand Down
7 changes: 3 additions & 4 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,16 @@ def install(context, package=None):
@task(iterable=['test'],
help={
'test': 'Limit unit test execution to specific tests. Must be given '
'multiple times to select several targets. See more: '
'https://github.com/CleanCut/green/blob/master/cli-options.txt#L5',
'multiple times to select several targets.'
})
def utest(context, test=None):
run(f'green {" ".join(test) if test else UNIT_TESTS}',
run(f'pytest {" ".join(test) if test else UNIT_TESTS} -q --disable-warnings',
env={'PYTHONPATH': str(SRCPATH)},
pty=(not system() == 'Windows'))

@task
def coverage(context):
run(f'green -r {str(UNIT_TESTS)}',
run(f'pytest --cov {UNIT_TESTS}',
env={'PYTHONPATH': str(SRCPATH)},
pty=(not system() == 'Windows'))
run('coverage html')
Expand Down
4 changes: 2 additions & 2 deletions tests/atest/oxygen_junit_tests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Oxygen's unit tests should pass
[Tags] oxygen-own-junit
Remove file ${JUNIT XML FILE}
File should not exist ${JUNIT XML FILE}
${green}= Get command green
${pytest}= Get command pytest
Run JUnit ${JUNIT XML FILE}
... ${green} -j ${JUNIT XML FILE} ${EXECDIR}
... ${pytest} --junit-xml\=${JUNIT XML FILE} ${EXECDIR}
File should exist ${JUNIT XML FILE}

*** Keywords ***
Expand Down
12 changes: 8 additions & 4 deletions tests/utest/oxygen/test_oxygen_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from argparse import ArgumentParser
from argparse import ArgumentParser, Namespace
from pathlib import Path
from subprocess import check_output, run, STDOUT, CalledProcessError
from tempfile import mkstemp
Expand All @@ -25,11 +25,15 @@ class TestOxygenCLIEntryPoints(TestCase):
quite a hack: https://coverage.readthedocs.io/en/latest/subprocess.html
'''

def tearDown(self):
@classmethod
def tearDownClass(cls):
with open(ORIGINAL_CONFIG_FILE, 'r') as og:
with open(CONFIG_FILE, 'w') as config:
config.write(og.read())

def tearDown(self):
self.tearDownClass()

def test_main_level_entrypoint(self):
self.verify_cli_help_text('python -m oxygen --help')
self.verify_cli_help_text('python -m oxygen -h')
Expand Down Expand Up @@ -112,7 +116,6 @@ def test_add_config(self):

self._run(f'python -m oxygen --add-config {filepath}')


with open(CONFIG_FILE, 'r') as f:
config_content = f.read()
self._validate_handler_names(config_content)
Expand Down Expand Up @@ -169,7 +172,8 @@ def test_run(self, mock_parse_args, mock_robot_iface):

def test_parse_args(self):
'''verifies that `parse_args()` returns a dictionary'''
p = ArgumentParser()
p = create_autospec(ArgumentParser)
p.parse_args.return_value = create_autospec(Namespace)

retval = self.cli.parse_args(p)

Expand Down
11 changes: 10 additions & 1 deletion tests/utest/zap/test_zap_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import sys

from unittest import TestCase
from unittest.mock import ANY, Mock, create_autospec, patch

from robot.running.model import TestSuite

from oxygen.oxygen import OxygenCLI
from ..helpers import RESOURCES_PATH

Expand All @@ -16,6 +19,12 @@ def setUp(self):
self.mock = Mock()
self.mock.running.build_suite = Mock(return_value=self.expected_suite)

def tearDown(self):
self.cli = None
self.handler = None
self.expected_suite = None
self.mock = None

def test_cli(self):
self.assertEqual(
self.handler.cli(),
Expand Down Expand Up @@ -81,7 +90,7 @@ def test_cli_run_with_accepted_risk_level(self, mock_robot_iface):
def test_cli_run_with_required_confidence_level(self, mock_robot_iface):
mock_robot_iface.return_value = self.mock

cmd_args = f"oxygen oxygen.zap {self.ZAP_XML} " "--required-confidence-level 3"
cmd_args = f"oxygen oxygen.zap {self.ZAP_XML} --required-confidence-level 3"
with patch.object(sys, "argv", cmd_args.split()):
self.cli.run()

Expand Down

0 comments on commit 5bf9f29

Please sign in to comment.