Skip to content

Commit ed7d8de

Browse files
committed
feat: update build.sh to use cmake, added pytest tests
1 parent a072f12 commit ed7d8de

File tree

7 files changed

+189
-22
lines changed

7 files changed

+189
-22
lines changed

.gitignore

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,150 @@ sc
3737
*.app
3838

3939
# End of https://www.toptal.com/developers/gitignore/api/fortran
40+
### Python ###
41+
# Byte-compiled / optimized / DLL files
42+
__pycache__/
43+
*.py[cod]
44+
*$py.class
4045

46+
# C extensions
47+
*.so
48+
49+
# Distribution / packaging
50+
.Python
51+
build/
52+
develop-eggs/
53+
dist/
54+
downloads/
55+
eggs/
56+
.eggs/
57+
parts/
58+
sdist/
59+
var/
60+
wheels/
61+
pip-wheel-metadata/
62+
share/python-wheels/
63+
*.egg-info/
64+
.installed.cfg
65+
*.egg
66+
MANIFEST
67+
68+
# PyInstaller
69+
# Usually these files are written by a python script from a template
70+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
71+
*.manifest
72+
*.spec
73+
74+
# Installer logs
75+
pip-log.txt
76+
pip-delete-this-directory.txt
77+
78+
# Unit test / coverage reports
79+
htmlcov/
80+
.tox/
81+
.nox/
82+
.coverage
83+
.coverage.*
84+
.cache
85+
nosetests.xml
86+
coverage.xml
87+
*.cover
88+
*.py,cover
89+
.hypothesis/
90+
.pytest_cache/
91+
pytestdebug.log
92+
93+
# Translations
94+
*.mo
95+
*.pot
96+
97+
# Django stuff:
98+
*.log
99+
local_settings.py
100+
db.sqlite3
101+
db.sqlite3-journal
102+
103+
# Flask stuff:
104+
instance/
105+
.webassets-cache
106+
107+
# Scrapy stuff:
108+
.scrapy
109+
110+
# Sphinx documentation
111+
docs/_build/
112+
doc/_build/
113+
114+
# PyBuilder
115+
target/
116+
117+
# Jupyter Notebook
118+
.ipynb_checkpoints
119+
120+
# IPython
121+
profile_default/
122+
ipython_config.py
123+
124+
# pyenv
125+
.python-version
126+
127+
# pipenv
128+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
129+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
130+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
131+
# install all needed dependencies.
132+
#Pipfile.lock
133+
134+
# poetry
135+
#poetry.lock
136+
137+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
138+
__pypackages__/
139+
140+
# Celery stuff
141+
celerybeat-schedule
142+
celerybeat.pid
143+
144+
# SageMath parsed files
145+
*.sage.py
146+
147+
# Environments
148+
# .env
149+
.env/
150+
.venv/
151+
env/
152+
venv/
153+
ENV/
154+
env.bak/
155+
venv.bak/
156+
pythonenv*
157+
158+
# Spyder project settings
159+
.spyderproject
160+
.spyproject
161+
162+
# Rope project settings
163+
.ropeproject
164+
165+
# mkdocs documentation
166+
/site
167+
168+
# mypy
169+
.mypy_cache/
170+
.dmypy.json
171+
dmypy.json
172+
173+
# Pyre type checker
174+
.pyre/
175+
176+
# pytype static type analyzer
177+
.pytype/
178+
179+
# operating system-related files
180+
# file properties cache/storage on macOS
181+
*.DS_Store
182+
# thumbnail cache on Windows
183+
Thumbs.db
184+
185+
# profiling data
186+
.prof

build.sh

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,7 @@ set -o errexit
44
set -o nounset
55
set -o pipefail
66

7-
ENVIRONMENT=${1:-dev}
8-
9-
if [[ "$ENVIRONMENT" == "dev" ]]; then
10-
gfortran -Wall -Wextra -g -Wpedantic -std=f2003 -Wimplicit-interface src/*Component.f03 src/*CLI.f03 src/Main.f03 -o test/sc
11-
elif [[ "$ENVIRONMENT" == "cli" ]]; then
12-
mkdir -p target/cli
13-
gfortran -Wall -Wextra -Wpedantic -std=f2003 -Wimplicit-interface src/*Component.f03 src/*CLI.f03 src/Main.f03 -o target/cli/simplecrop
14-
elif [[ "$ENVIRONMENT" == "lib" ]]; then
15-
mkdir -p target/lib
16-
gfortran -Wall -Wextra -Wpedantic -std=f2003 -Wimplicit-interface src/*Component.f03 src/*CLI.f03 src/Main.f03 -c
17-
ar crs libsimplecrop.a *.o
18-
mv libsimplecrop.a target/lib
19-
fi
7+
mkdir -p src/_build
8+
cd src/_build
9+
cmake ../
10+
make all

src/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_build

test.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import pytest
3+
import shutil
4+
import subprocess
5+
6+
7+
@pytest.fixture(scope='session', autouse=True)
8+
def initialize(request):
9+
if not os.path.exists('test/data'):
10+
shutil.copytree('data', 'test/data')
11+
root = os.path.dirname(os.path.realpath(__file__))
12+
subprocess.run([os.path.join(root, 'src/_build/simplecrop')], check=True, cwd=os.path.join(root, 'test'))
13+
14+
15+
def read_soil_lines(fname):
16+
with open(fname) as f:
17+
content = f.read()
18+
lines = content.splitlines()
19+
return lines[7:]
20+
21+
22+
def read_plant_lines(fname):
23+
with open(fname) as f:
24+
content = f.read()
25+
return content.splitlines()
26+
27+
28+
def test_soil_output():
29+
soil_orig = read_soil_lines('output/soil.out')
30+
soil_new = read_soil_lines('test/output/soil.out')
31+
assert soil_orig == soil_new
32+
33+
34+
def test_plant_output():
35+
plant_orig = read_plant_lines('output/plant.out')
36+
plant_new = read_plant_lines('test/output/plant.out')
37+
assert plant_orig == plant_new

test.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data

test/data

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)