Skip to content

Commit

Permalink
Testing Framework and initial tests (#2)
Browse files Browse the repository at this point in the history
* test configurations, main window tests added, pytest additional dependencies added, argument parser updated
* ruff D code added, docstrings in functions and files everywhere
* pytest-xvfb added
  • Loading branch information
mpatrou authored Nov 4, 2024
1 parent 1978169 commit 4747d27
Show file tree
Hide file tree
Showing 15 changed files with 355 additions and 17 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ jobs:
shell: bash -l {0}
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
- uses: mamba-org/setup-micromamba@v1
with:
auto-update-conda: true
channels: conda-forge,defaults
use-mamba: true
environment-file: environment.yml
activate-environment: hyspecplanningtools_dev
cache-environment-key: ${{ runner.os }}-env-${{ hashFiles('**/environment.yml') }}
cache-downloads-key: ${{ runner.os }}-downloads-${{ hashFiles('**/environment.yml') }}
condarc: |
channels:
- conda-forge
- anaconda
- name: install in editable mode
run: |
echo "installing in editable mode"
python -m pip install -e .
- name: run unit tests
run: |
echo "running unit tests"
python -m pytest --cov=src --cov-report=xml --cov-report=term-missing tests/
echo "running unit tests with coverage"
python -m pytest --cov=src --cov-report=xml --cov-report=term
- name: upload coverage to codecov
uses: codecov/codecov-action@v4
if:
Expand Down
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Documentation Configuration"""

# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
Expand Down
4 changes: 3 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- qtpy
- numpy
- scipy
- matplotlib
- matplotlib <3.9 #resolves pyside 6 error
- pre-commit
# package building:
- versioningit
Expand All @@ -26,5 +26,7 @@ dependencies:
- myst-parser # required for parsing markdown files
# test: list all test dependencies here
- pytest
- pytest-qt
- pytest-cov
- pytest-xdist
- pytest-xvfb
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ markers = [

[tool.ruff]
line-length = 120
select = ["A", "ARG","ASYNC","BLE","C90", "E", "F", "I", "N", "UP032", "W"]

[tool.ruff.lint]
select = ["A", "ARG","ASYNC","BLE","C90", "D", "E", "F", "I", "N", "UP032", "W"]
ignore = ["D203", # conflict with D211
"D213", # conflict with D212
"D205", # conflicts
"D400", "D401","D404", "D415" # Unnecessary
]
# Add additional 3rd party tool configuration here as needed
9 changes: 9 additions & 0 deletions src/hyspecplanningtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@
from ._version import __version__ # noqa: F401
except ImportError:
__version__ = "unknown"


def HyspecPlanningTool(): # noqa: N802
"""This is needed for backward compatibility because mantid workbench does
"from hyspecplanningtools import HyspecPlanningTool"
"""
from .hyspecplanningtools import HyspecPlanningTool as hyspecplanningtools # noqa: E501, N813

return hyspecplanningtools()
1 change: 1 addition & 0 deletions src/hyspecplanningtools/configuration_template.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[global.other]
#url to documentation
help_url = https://github.com/neutrons/HyspecPlanningTools/blob/next/README.md
3 changes: 2 additions & 1 deletion src/hyspecplanningtools/home/home_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
logger = logging.getLogger("hyspecplanningtools")


class HomeModel: # pylint: disable=too-many-public-methods
class HomeModel:
"""Main model"""

def __init__(self):
"""Constructor"""
return
3 changes: 2 additions & 1 deletion src/hyspecplanningtools/home/home_presenter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Presenter for the Main tab"""


class HomePresenter: # pylint: disable=too-many-public-methods
class HomePresenter:
"""Main presenter"""

def __init__(self, view, model):
"""Constructor"""
self._view = view
self._model = model

Expand Down
3 changes: 2 additions & 1 deletion src/hyspecplanningtools/home/home_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from qtpy.QtWidgets import QHBoxLayout, QWidget


class Home(QWidget): # pylint: disable=too-many-public-methods
class Home(QWidget):
"""Main widget"""

def __init__(self, parent=None):
"""Constructor"""
super().__init__(parent)

layout = QHBoxLayout()
Expand Down
15 changes: 10 additions & 5 deletions src/hyspecplanningtools/hyspecplanningtools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Main Qt application"""

import argparse
import logging
import sys

Expand All @@ -18,11 +19,13 @@ class HyspecPlanningTool(QMainWindow):
__instance = None

def __new__(cls):
if HyspecPlanningTool.__instance is None:
HyspecPlanningTool.__instance = QMainWindow.__new__(cls) # pylint: disable=no-value-for-parameter
return HyspecPlanningTool.__instance
"""Create new instance of the HyspecPlanningTool"""
if not cls.__instance:
cls.__instance = super(HyspecPlanningTool, cls).__new__(cls)
return cls.__instance

def __init__(self, parent=None):
"""Constructor"""
super().__init__(parent)
logger.info(f"HyspecPlanningTool version: {__version__}")
config = Configuration()
Expand All @@ -44,8 +47,10 @@ def __init__(self, parent=None):

def gui():
"""Main entry point for Qt application"""
input_flags = sys.argv[1::]
if "--v" in input_flags or "--version" in input_flags:
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--version", help="print the version", action="store_true")
args = parser.parse_args()
if args.version:
print(__version__)
sys.exit()
else:
Expand Down
1 change: 1 addition & 0 deletions src/hyspecplanningtools/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MainWindow(QWidget):
"""Main widget"""

def __init__(self, parent=None):
"""Constructor"""
super().__init__(parent)

### Create tabs here ###
Expand Down
29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""pytest configuration"""

import os
from configparser import ConfigParser

import pytest

from hyspecplanningtools import HyspecPlanningTool


@pytest.fixture
def hyspec_app(qapp): # noqa: ARG001
"""Create a HyspecPlanningTool app"""
app = HyspecPlanningTool()
app.show()
return app


@pytest.fixture(scope="session")
def user_conf_file(tmp_path_factory, request):
"""Fixture to create a custom configuration file in tmp_path"""
# custom configuration file
config_data = request.param
user_config = ConfigParser(allow_no_value=True)
user_config.read_string(config_data)
user_path = os.path.join(tmp_path_factory.mktemp("data"), "test_config.ini")
with open(user_path, "w", encoding="utf8") as config_file:
user_config.write(config_file)
return user_path
Loading

0 comments on commit 4747d27

Please sign in to comment.