Skip to content

Commit

Permalink
Merge pull request #2 from Shimwell/develop
Browse files Browse the repository at this point in the history
Adding tests to tdd
  • Loading branch information
shimwell authored Apr 15, 2021
2 parents 3f5c2a2 + 1b83895 commit 8d94d7b
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 56 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This yml file will trigger a Github Actions event that builds and upload the
# Python package to PiPy. This makes use of Twine and is triggered when a push
# to the master branch occures. For more information see:
# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
28 changes: 13 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This Dockerfile creates an enviroment for testing the python package
# remove_dagmc_tags

FROM ubuntu:18.04
FROM continuumio/miniconda3:4.9.2

ENV DEBIAN_FRONTEND=noninteractive

Expand Down Expand Up @@ -29,34 +29,32 @@ RUN apt-get --yes install libeigen3-dev && \
apt-get --yes install liblapack-dev && \
apt-get --yes install libnetcdf-dev && \
apt-get --yes install libtbb-dev && \
apt-get --yes install libglfw3-dev
apt-get --yes install libglfw3-dev && \
apt-get --yes install cmake && \
apt-get --yes install git

# Clone and install MOAB

RUN pip install --upgrade numpy cython && \
mkdir MOAB && \
RUN pip install --upgrade numpy cython
RUN mkdir MOAB && \
cd MOAB && \
mkdir build && \
git clone --single-branch --branch 5.2.1 --depth 1 https://bitbucket.org/fathomteam/moab.git && \
mkdir build && \
cd build && \
cmake ../moab -DENABLE_HDF5=ON \
-DENABLE_NETCDF=ON \
-DENABLE_FORTRAN=OFF \
-DENABLE_BLASLAPACK=OFF \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=/MOAB && \
make 2 && \
make 2 install && \
rm -rf * && \
make && \
make install && \
cmake ../moab -DENABLE_HDF5=ON \
-DENABLE_PYMOAB=ON \
-DENABLE_FORTRAN=OFF \
-DBUILD_SHARED_LIBS=ON \
-DENABLE_BLASLAPACK=OFF \
-DCMAKE_INSTALL_PREFIX=/MOAB && \
make 2 && \
make 2 install

# cd pymoab && \
# bash install.sh && \
# python setup.py install
make install && \
cd pymoab && \
bash install.sh && \
python setup.py install
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ remove-dagmc-tags -i dagmc.h5m -o dagmc_no_graveyard.h5m -t graveyard
- the ```-i``` or ```--input``` argument specifies the input h5m file
- the ```-o``` or ```--output``` argument specifies the output h5m file
- the ```-t``` or ```--tags``` argument specifies the tags to remove.
- the ```-v``` or ```--verbose``` argument enables (true) or disables (false) the printing of additional details

Multiple tags can also be removed. This example removes three tags from the dagmc.h5m file

Expand All @@ -23,8 +24,26 @@ remove-dagmc-tags -i dagmc.h5m -o dagmc_output.h5m -t mat:graveyard mat:vacuum r

# Python API usage

Removing a single tag called ```mat:graveyard``` from the dagmc.h5m file.
```python
from remove_dagmc_tags import
from remove_dagmc_tags import remove_tags

remove_tags(
input='dagmc.h5m',
output='output.h5m',
tags='mat:graveyard'
)
```

Removing two tags called ```mat:graveyard``` and ```reflective``` from the dagmc.h5m file.
```python
from remove_dagmc_tags import remove_tags

remove_tags(
input='dagmc.h5m',
output='output.h5m',
tags='reflective'
)
```

# Installation
Expand Down
54 changes: 41 additions & 13 deletions tests/test_command_line_tool.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@

import json
import os
import unittest
from pathlib import Path

import cadquery as cq
import paramak
import pytest
import urllib


class TestReactor(unittest.TestCase):

# def setUp(self):
# test_shape = paramak.RotateStraightShape(
# points=[(0, 0), (0, 20), (20, 20)])
if Path('dagmc.h5m').is_file() is False:
test_h5m_file_url = 'https://github.com/Shimwell/fusion_example_for_openmc_using_paramak/raw/main/dagmc.h5m'

# self.test_reactor = paramak.Reactor([test_shape])
urllib.request.urlretrieve(test_h5m_file_url, 'dagmc.h5m')

def test_removal_of_graveyard(self):
def test_removal_of_reflecting_tag(self):
def test_removal_of_two_tags(self):
def test_conversion_to_vtk(self):
def test_conversion_to_vtk_without_graveyard(self):
def test_conversion_to_vtk_without_graveyard_or_reflecting_tag(self):
def test_removal_of_multiple_tags(self):

# test_removal_of_reflecting_tag
os.system('rm dagmc_output.h5m')
os.system('remove-dagmc-tags -i dagmc.h5m -o dagmc_output.h5m -t reflective')
assert Path('dagmc_output.h5m').exists
assert Path('dagmc_output.h5m').stat().st_size < Path('dagmc.h5m').stat().st_size
size_with_out_reflective = Path('dagmc_output.h5m').stat().st_size

# test_removal_of_graveyard
os.system('rm dagmc_output.h5m')
os.system('remove-dagmc-tags -i dagmc.h5m -o dagmc_output.h5m -t mat:graveyard')
assert Path('dagmc_output.h5m').exists
assert Path('dagmc_output.h5m').stat().st_size < Path('dagmc.h5m').stat().st_size
size_with_out_graveyard = Path('dagmc_output.h5m').stat().st_size

os.system('rm dagmc_output.h5m')
os.system('remove-dagmc-tags -i dagmc.h5m -o dagmc_output.h5m -t reflective mat:graveyard')
assert Path('dagmc_output.h5m').exists
assert Path('dagmc_output.h5m').stat().st_size < size_with_out_graveyard
assert Path('dagmc_output.h5m').stat().st_size < size_with_out_reflective

def test_conversion_to_vtk_with_multiple_tag_removal(self):

os.system('rm dagmc_output.vtk')
os.system('remove-dagmc-tags -i dagmc.h5m -o dagmc_output.vtk -t reflective')
assert Path('dagmc_output.vtk').exists

# test_conversion_to_vtk_without_graveyard(self):
os.system('rm dagmc_output.vtk')
os.system('remove-dagmc-tags -i dagmc.h5m -o dagmc_output.vtk -t mat:graveyard')
assert Path('dagmc_output.vtk').exists

# test_conversion_to_vtk_without_graveyard_or_reflecting_tag(self):
os.system('rm dagmc_output.vtk')
os.system('remove-dagmc-tags -i dagmc.h5m -o dagmc_output.vtk -t reflective mat:graveyard')
assert Path('dagmc_output.vtk').exists


if __name__ == "__main__":
Expand Down
59 changes: 32 additions & 27 deletions tests/test_python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def test_removal_of_graveyard(self):
remove_tags(
input='dagmc.h5m',
output='output.h5m',
tags='graveyard',
tags='mat:graveyard',
)

assert 'graveyard' in find_tags('dagmc.h5m')
assert 'graveyard' not in find_tags('output.h5m')
assert Path('output.h5m').stat < Path('dagmc.h5m').stat
assert 'mat:graveyard' in find_tags('dagmc.h5m')
assert 'mat:graveyard' not in find_tags('output.h5m')
assert Path('output.h5m').stat().st_size < Path('dagmc.h5m').stat().st_size

def test_removal_of_reflective_tag(self):
"""removes a single tag called reflective, passed in as a list of one"""
Expand All @@ -41,61 +41,66 @@ def test_removal_of_reflective_tag(self):

assert 'reflective' in find_tags('dagmc.h5m')
assert 'reflective' not in find_tags('output.h5m')
assert Path('output.h5m').stat < Path('dagmc.h5m').stat
assert Path('output.h5m').stat().st_size < Path('dagmc.h5m').stat().st_size

def test_removal_of_two_tags(self):
"""removes two tags called graveyard and reflective"""

remove_tags(
input='dagmc.h5m',
output='output.h5m',
tags=['graveyard', 'reflective'],
tags=['mat:graveyard', 'reflective'],
)

assert 'reflective' in find_tags('dagmc.h5m')
assert 'reflective' not in find_tags('output.h5m')
assert 'graveyard' in find_tags('dagmc.h5m')
assert 'graveyard' not in find_tags('output.h5m')
assert Path('output.h5m').stat < Path('dagmc.h5m').stat

def test_conversion_to_h5m(self):
remove_tags(
input='dagmc.h5m',
output='output.h5m',
# tags is not set so this is a straight resave
)
assert Path('output.h5m').stat == Path('dagmc.h5m').stat
assert 'mat:graveyard' in find_tags('dagmc.h5m')
assert 'mat:graveyard' not in find_tags('output.h5m')
assert Path('output.h5m').stat().st_size < Path('dagmc.h5m').stat().st_size

# If processed file is the same as the input file then this test can be performed
# def test_conversion_to_h5m(self):
# remove_tags(
# input='dagmc.h5m',
# output='output.h5m',
# verbose=True
# # tags is not set so this is a save of the same file with no change
# )
# assert Path('output.h5m').stat().st_size == Path('dagmc.h5m').stat().st_size

def test_conversion_to_vtk(self):
remove_dagmc_tags.h5m_to_vtk(
remove_tags(
input='dagmc.h5m',
output='output.vtk',
# tags is not set so this is a straight conversion
)
assert Path('output.vtk').is_file()

def test_conversion_to_vtk_without_graveyard(self):
remove_dagmc_tags.h5m_to_vtk(
returned_var = remove_tags(
input='dagmc.h5m',
output='output.vtk',
tags=['graveyard'],
tags=['mat:graveyard'],
)
assert Path('output.vtk').is_file()
assert ['output.vtk'] == returned_var

def test_conversion_to_vtk_without_graveyard_or_reflective_tag(self):
remove_dagmc_tags.h5m_to_vtk(
remove_tags(
input='dagmc.h5m',
output='output.vtk',
tags=['reflective'],
tags=['mat:graveyard'],
)
remove_dagmc_tags.h5m_to_vtk(
remove_tags(
input='dagmc.h5m',
output='output_big.vtk',
tags=['graveyard', 'reflective'],
output='output_small.vtk',
tags=['mat:graveyard', 'reflective'],
)
assert Path('output_big.vtk').is_file()
assert Path('output_small.vtk').is_file()
assert Path('output.vtk').is_file()
assert Path('output.vtk').stat < Path('output_big.vtk').stat
# This test will work if tags require space in the file
# assert Path('output.vtk').stat().st_size > Path('output_small.vtk').stat().st_size


if __name__ == "__main__":
unittest.main()

0 comments on commit 8d94d7b

Please sign in to comment.