Skip to content

Commit

Permalink
chore: Expand tests and test coverage. (#9)
Browse files Browse the repository at this point in the history
Rename workflow.

Fix dependencies.

Linting.

chore: Expand tests and test coverage.

Signed-off-by: Caroline Russell <[email protected]>
  • Loading branch information
cerrussell authored Jan 21, 2024
1 parent afc6b69 commit 865494d
Show file tree
Hide file tree
Showing 13 changed files with 2,230,463 additions and 156 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Python matrix CI
name: OS matrix CI

on:
push:
branches:
- master
paths-ignore:
- '**/README.md'
- 'dockertests.yml'
- 'dockertests.yml'
- 'python-publish.yml'
- 'pre-commit.yml'
- 'release.yml'
- 'test.yml'
pull_request:
workflow_dispatch:

Expand All @@ -27,7 +27,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
python-version: "3.11"
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
Expand All @@ -36,4 +36,6 @@ jobs:
python3 -m pip install .[dev]
- name: Tox
run: |
python3 -m tox
python3 -m tox
coverage run -m pytest test
coverage report
54 changes: 1 addition & 53 deletions atom_tools/cli/commands/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,65 +26,13 @@ class ConvertCommand(Command):

name = 'convert'
description = 'Convert an atom slice to a different format'
# arguments = [
# argument(
# 'format',
# 'Destination format',
# default='openapi3.1.0',
# optional=True,
# ),
# argument(
# 'bom-file',
# 'Path to bom generated by cdxgen',
# optional=True,
# default=None,
# ),
# argument(
# 'usages-slice',
# 'Usages slice file',
# optional=True,
# default=None,
# ),
# argument(
# 'reachables-slice',
# 'Reachables slice file',
# optional=True,
# default=None,
# ),
# argument(
# 'language',
# 'Language',
# optional=True,
# default='Java',
# )
# ]
# options = [
# option(
# 'format',
# 'f',
# 'Destination format',
# flag=False,
# default='openapi3.1.0',
# ),
# option(
# 'bom-file',
# 'b',
# 'Path to bom generated by cdxgen',
# ),
# option('usages-slice', 'u', 'Usages slice file', flag=False),
# option(
# 'reachables-slice',
# 'r',
# 'Reachables slice file',
# ),
# ]
options = [
option(
'format',
'f',
'Destination format',
flag=False,
default='openapi3.1.0',
default='openapi3.0.1',
),
option(
'usages-slice',
Expand Down
19 changes: 6 additions & 13 deletions atom_tools/lib/slices.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ def import_slice(filename):
Warnings:
If the JSON file is not a valid usage slice, a warning is logged.
"""
if not filename:
return {}
try:
with open(filename, 'r', encoding='utf-8') as f:
content = json.load(f)
Expand All @@ -69,9 +67,7 @@ def import_slice(filename):
f'Failed to locate the usages slice file in the location '
f'specified: {filename}')

logger.warning(f'This does not appear to be a valid usage slice: '
f'{filename}\nPlease check that you specified the '
f'correct usages slice file.')
logger.warning('Failed to load usages slice.')
return {}

def generate_endpoints(self):
Expand Down Expand Up @@ -160,7 +156,8 @@ def filter_matches(self, matches, code):
return filtered_matches

for m in matches:
if m[0] not in ('.', '@') and '/' in m and (self.language not in (
if m and m[0] not in ('.', '@') and '/' in m and (
self.language not in (
'js', 'ts', 'javascript', 'typescript') or not (
m.startswith('application/') or m.startswith('text/'))):
nm = m.replace('"', '').replace("'", '').lstrip('/')
Expand Down Expand Up @@ -206,22 +203,18 @@ def import_slice(filename):
Warnings:
A warning is logged if the JSON file is not a valid slice.
"""
if not filename or not os.path.isfile(filename):
return []
try:
with open(filename, 'r', encoding='utf-8') as f:
content = json.load(f)
return content.get('reachables', [])
except (json.decoder.JSONDecodeError, UnicodeDecodeError):
logging.warning(
f'Failed to load usages slice: {filename}\nPlease check '
f'Failed to load reachables slice: {filename}\nPlease check '
f'that you specified a valid json file.')
except FileNotFoundError:
logging.warning(
f'Failed to locate the usages slice file in the location '
f'Failed to locate the reachables slice file in the location '
f'specified: {filename}')

logging.warning(
f'This does not appear to be a valid usage slice: {filename}\n'
f'Please check that you specified the correct usages slice file.')
logging.warning('Failed to load reachables slice.')
return []
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ atom-tools = "atom_tools.cli.application:main"
[project.optional-dependencies]
dev = [
"black",
"coverage",
"flake8",
"isort",
"pre-commit",
Expand Down
5 changes: 5 additions & 0 deletions test/data/invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"key": "objectSlices",
"value": [

}
Loading

0 comments on commit 865494d

Please sign in to comment.