-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from harmsm/main
added unit test
- Loading branch information
Showing
10 changed files
with
1,006 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# This workflow will install Python dependencies, run tests and flake8 across | ||
# platforms and python versions. | ||
|
||
name: ElliptiCBn | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
max-parallel: 3 | ||
matrix: | ||
os: [ubuntu-latest,macos-latest,windows-latest] | ||
python-version: ['3.7', '3.8', '3.9', '3.10' , '3.11', '3.12'] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: install ElliptiCBn | ||
run: | | ||
# platform specific packages | ||
python -m pip install . -vv -r requirements.txt | ||
- name: run flake8 | ||
run: | | ||
pip install flake8 | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
- name: run pytest coverage | ||
run: | | ||
pip install pytest | ||
pytest tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
echo "Running flake8" | ||
flake_test=`flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics` | ||
if [[ "${flake_test}" != 0 ]]; then | ||
echo "flake failed" | ||
exit | ||
fi | ||
|
||
rm -rf reports | ||
mkdir reports | ||
mkdir reports/junit | ||
mkdir reports/coverage | ||
mkdir reports/badges | ||
|
||
echo "Running flake8, aggressive" | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics > reports/flake.txt | ||
|
||
echo "Running coverage.py" | ||
coverage erase | ||
coverage run --branch -m pytest --junit-xml=reports/junit/junit.xml | ||
|
||
echo "Generating reports" | ||
coverage html | ||
mv htmlcov reports | ||
|
||
coverage xml | ||
mv coverage.xml reports/coverage/coverage.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import pytest | ||
import os | ||
import glob | ||
|
||
def get_files(base_dir): | ||
""" | ||
Traverse base_dir and return a dictionary that keys all files and some | ||
rudimentary *.ext expressions to absolute paths to those files. They keys | ||
will be things like "some_dir/test0/rocket.txt" mapping to | ||
"c:/some_dir/life/base_dir/some_dir/test0/rocket.txt". The idea is to have | ||
easy-to-read cross-platform keys within unit tests. | ||
Classes of keys: | ||
+ some_dir/test0/rocket.txt maps to a file (str) | ||
+ some_dir/test0/ maps to the test0 directory itself (str) | ||
+ some_dir/test0/*.txt maps to all .txt (list) | ||
+ some_dir/test0/* maps to all files or directories in the directory | ||
(list) | ||
Note that base_dir is *not* included in the keys. All are relative to that | ||
directory by :code:`os.path.basename(__file__)/{base_dir}`. | ||
Parameters | ||
---------- | ||
base_dir : str | ||
base directory for search. should be relative to test file location. | ||
Returns | ||
------- | ||
output : dict | ||
dictionary keying string paths to absolute paths | ||
""" | ||
|
||
containing_dir = os.path.dirname(os.path.realpath(__file__)) | ||
starting_dir = os.path.abspath(os.path.join(containing_dir,base_dir)) | ||
|
||
base_length = len(starting_dir.split(os.sep)) | ||
|
||
# Traverse starting_dir | ||
output = {} | ||
for root, dirs, files in os.walk(starting_dir): | ||
|
||
# path relative to base_dir as a list | ||
this_path = root.split(os.sep)[base_length:] | ||
|
||
# Build paths to specific files | ||
local_files = [] | ||
for file in files: | ||
local_files.append(os.path.join(root,file)) | ||
new_key = this_path[:] | ||
new_key.append(file) | ||
output["/".join(new_key)] = local_files[-1] | ||
|
||
# Build paths to patterns of file types | ||
patterns = {} | ||
ext = list(set([f.split(".")[-1] for f in local_files])) | ||
for e in ext: | ||
new_key = this_path[:] | ||
new_key.append(f"*.{e}") | ||
output["/".join(new_key)] = glob.glob(os.path.join(root,f"*.{e}")) | ||
|
||
# Build path to all files in this directory | ||
new_key = this_path[:] | ||
new_key.append("*") | ||
output["/".join(new_key)] = glob.glob(os.path.join(root,f"*")) | ||
|
||
# Build paths to directories in this directory | ||
for this_dir in dirs: | ||
new_key = this_path[:] | ||
new_key.append(this_dir) | ||
# dir without terminating / | ||
output["/".join(new_key)] = os.path.join(root,this_dir) | ||
|
||
# dir with terminating / | ||
new_key.append("") | ||
output["/".join(new_key)] = os.path.join(root,this_dir) | ||
|
||
return output | ||
|
||
@pytest.fixture(scope="module") | ||
def example_xyz(): | ||
return get_files(os.path.join("data","example-xyz")) |
Oops, something went wrong.