Skip to content

Commit

Permalink
Unit tests (#12)
Browse files Browse the repository at this point in the history
* Setup test framework using pytest

* Started adding tests for output module 

* Reformatted currently existing tests for geometry

* Minor refactor of parsing modules attributes and inheritance 

* Added pytest CI 

* Addresses #3, and #6

---------

Co-authored-by: lukashoermann200 <[email protected]>
  • Loading branch information
dylanbmorgan and lukashoermann200 authored Oct 31, 2024
1 parent 960134d commit 23e4cc1
Show file tree
Hide file tree
Showing 58 changed files with 4,640 additions and 2,363 deletions.
1 change: 1 addition & 0 deletions .github/workflows/interrogate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO
65 changes: 65 additions & 0 deletions .github/workflows/pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
release-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Build release distributions
run: |
# NOTE: put your own distribution build steps here.
poetry build
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: release-dists
path: dist/

pypi-publish:
runs-on: ubuntu-latest

needs:
- release-build

permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

# Dedicated environments with protections for publishing are strongly recommended.
environment:
name: pypi
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
# url: https://pypi.org/p/YOURPROJECT

steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v4
with:
name: release-dists
path: dist/

- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@6f7e8d9c0b1a2c3d4e5f6a7b8c9d0e1f2a3b4c5d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run the pyright checker
name: pyright

on:
push:
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: pytest

on:
push:
branches:
- master
pull_request:
branches:
- master

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Only run after linting has finished
# workflow_run:
# workflows: ['ruff']
# types: [completed]

jobs:
test:
runs-on: ubuntu-latest
# TODO run on all supported versions of the project
# strategy:
# matrix:
# python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: abatilo/actions-poetry@v2
- name: Install the project dependencies
run: poetry install --with=dev
- name: Run the tests
run: poetry run -- pytest tests --cov=dfttools --cov-report xml

# TODO when approved for the maurergroup organisation
# - name: Coveralls GitHub Action
# uses: coverallsapp/[email protected]
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# parallel: true # Enable parallel support for Coveralls if needed
4 changes: 3 additions & 1 deletion .github/workflows/ruff.yml → .github/workflows/ruff.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run the ruff linter and formatter
name: ruff

on:
push:
Expand All @@ -12,6 +12,7 @@ on:
jobs:
ruff-lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
Expand All @@ -22,6 +23,7 @@ jobs:
ruff-format:
runs-on: ubuntu-latest
needs: ruff-lint

steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and deploy Sphinx docs
name: Sphinx

on:
# Runs on pushes targeting the default branch
Expand Down Expand Up @@ -32,14 +32,11 @@ jobs:
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Poetry
uses: abatilo/actions-poetry@v2
- uses: abatilo/actions-poetry@v2
- name: Install the project dependencies
run: poetry install --with=docs
- name: Build HTML
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,9 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Tests
tests/.aims_bin_loc
tests/fixtures/custom_bin_aims_calcs

# Tutorials
tutorials/temp/
23 changes: 23 additions & 0 deletions dfttools/base_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os.path
from typing import List


class BaseParser:
Expand Down Expand Up @@ -39,3 +40,25 @@ def __init__(self, supported_files, **kwargs):
else:
with open(kwargs[kwarg], "r") as f:
self.file_contents[kwarg] = f.readlines()

def __str__(self) -> str:
if self.lines is None or self.lines == "":
raise ValueError("Could not find file contents.")
else:
return "".join(self.lines)

@property
def lines(self) -> List[str]:
return self._lines

@lines.setter
def lines(self, value: List[str]):
self._lines = value

@property
def path(self) -> str:
return self._path

@path.setter
def path(self, value: str):
self._path = value
Loading

0 comments on commit 23e4cc1

Please sign in to comment.