Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor testing #190

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .github/workflows/test_castep_outputs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: Python application
on:
push:
branches: [ "main" ]
pull_request:
pull_request:
types:
- opened
- synchronize
Expand All @@ -17,9 +17,9 @@ permissions:

jobs:
build:

runs-on: ubuntu-latest

permissions:
pull-requests: write
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
Expand All @@ -33,8 +33,12 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruamel.yaml coverage
pip install ".[test,ruamel,yaml]"
- name: Run tests
run: |
PYTHONPATH=. coverage run -m unittest discover castep_outputs/test/
coverage report
pytest --doctest-modules --cov=castep_outputs --cov-report xml:coverage.xml
- name: Get Coverage
uses: orgoro/[email protected]
with:
coverageFile: coverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
22 changes: 0 additions & 22 deletions castep_outputs/test/gen_data.py

This file was deleted.

9 changes: 0 additions & 9 deletions castep_outputs/test/test_docstrings.py

This file was deleted.

191 changes: 0 additions & 191 deletions castep_outputs/test/test_dumpers.py

This file was deleted.

47 changes: 0 additions & 47 deletions castep_outputs/test/test_filters.py

This file was deleted.

31 changes: 16 additions & 15 deletions castep_outputs/utilities/dumpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@

import json
import pprint
from contextlib import suppress
from typing import Any, Callable, TextIO

try:
from ruamel import yaml
_YAML_TYPE = None

with suppress(ImportError):
import yaml
_YAML_TYPE = "pyyaml"

with suppress(ImportError):
from ruamel import yaml as ruamel
_YAML_TYPE = "ruamel"
except ImportError:
try:
import yaml
_YAML_TYPE = "yaml"
except ImportError:
_YAML_TYPE = None


#: Dumping function protocol.
Expand Down Expand Up @@ -45,11 +46,11 @@ def ruamel_dumper(data: Any, file: TextIO):
file
File to dump to.
"""
yaml_eng = yaml.YAML(typ="unsafe")
yaml_eng = ruamel.YAML(typ="unsafe")
yaml_eng.dump(data, file)


def yaml_dumper(data: Any, file: TextIO):
def pyyaml_dumper(data: Any, file: TextIO):
"""
YAML (pyyaml) format dumper.

Expand Down Expand Up @@ -117,21 +118,21 @@ def get_dumpers(dump_fmt: str) -> Dumper:
SUPPORTED_FORMATS
Acceptable values for `dump_fmt`.
"""
if dump_fmt not in SUPPORTED_FORMATS:
raise ValueError(f"Cannot output in {dump_fmt} format. "
f"Valid keys are: {', '.join(SUPPORTED_FORMATS.keys())}")

if dump_fmt == "yaml":
if _YAML_TYPE is None:
raise ImportError("Couldn't find valid yaml dumper (ruamel.yaml / yaml)"
"please install and try again.")
dump_fmt = _YAML_TYPE

if dump_fmt not in SUPPORTED_FORMATS:
raise ValueError(f"Cannot output in {dump_fmt} format. "
f"Valid keys are: {', '.join(SUPPORTED_FORMATS.keys())}")

return SUPPORTED_FORMATS[dump_fmt]

#: Currently supported dumpers.
SUPPORTED_FORMATS: dict[str, Dumper] = {"json": json_dumper,
"ruamel": ruamel_dumper,
"yaml": yaml_dumper,
"pyyaml": pyyaml_dumper,
"pprint": pprint_dumper,
"print": print_dumper}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ruamel = ["ruamel.yaml>=0.17.22"]
yaml = ["pyYAML>=3.13"]
docs = ["jupyter-book>=0.13.1", "sphinx-book-theme>=0.3.3", "sphinx-argparse>=0.4.0", "sphinx-autodoc-typehints"]
lint = ["ruff==0.8.0"]
test = ["pytest==8.3.4", "pytest-cov==5.0.0"]

[project.scripts]
castep_outputs = "castep_outputs.cli.castep_outputs_main:main"
Expand Down
File renamed without changes.
Loading