Skip to content

Commit

Permalink
Refactor and test examples
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Paine <[email protected]>
  • Loading branch information
timkpaine committed Feb 13, 2024
1 parent 388eb26 commit 6b90b42
Show file tree
Hide file tree
Showing 43 changed files with 44 additions and 67 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ lib-cov
coverage
junit.xml

# Temp files
tmp*.*

# Documentation
docs/_build/
/site
Expand All @@ -100,9 +103,6 @@ csp/include/
csp/lib/
*.so
*.tsbuildinfo
csp/extension
csp/nbextension
csp/labextension

# Jupyter / Editors
.ipynb_checkpoints
Expand Down
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ prune _skbuild
include vcpkg.json
prune vcpkg

# IDE / VCS files
# IDE / VCS / docs files
prune .git
prune .github
prune .vscode
prune ci
prune examples
exclude .clang-format
exclude .gitattributes
exclude .gitignore
Expand Down
52 changes: 0 additions & 52 deletions csp/examples/e_03_numba_simple_example.py

This file was deleted.

Empty file.
26 changes: 26 additions & 0 deletions csp/tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import importlib
import os.path
import pytest
import sys

EXAMPLES_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "examples"))

# make examples importable without keeping in source tree
sys.path.append(EXAMPLES_ROOT)

def _get_module(folder, filename):
# Don't fail during test gathering
try:
return importlib.import_module(f"{folder}.{filename.replace('.py', '')}")
except BaseException:
return None

def _get_modules_to_test(folder):
return [(file, _get_module(folder, file)) for file in os.listdir(os.path.join(EXAMPLES_ROOT, "1_basics")) if file.endswith(".py")]

class TestExamples:
@pytest.mark.parametrize("filename,module", _get_modules_to_test("1_basics"))
def test_1_basics(self, filename, module):
assert module.main
module.main()
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ def my_graph():

def main():
start = datetime(2020, 1, 1)
show_graph = False
if show_graph:
csp.showgraph.show_graph(my_graph)
else:
csp.run(my_graph, starttime=start)
csp.run(my_graph, starttime=start)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ def my_graph():
csp.print("spread2", s2)


def main():
# open in graphviz viewer
# csp.show_graph(my_graph)
# or output to file
csp.show_graph(my_graph, graph_filename="tmp.png")
csp.run(my_graph, starttime=datetime(2020, 3, 1), endtime=timedelta(seconds=10))

if __name__ == "__main__":
csp.show_graph(my_graph)
realtime = True
if realtime:
csp.run(my_graph, starttime=datetime.utcnow(), endtime=timedelta(seconds=10), realtime=True)
else:
csp.run(my_graph, starttime=datetime(2020, 3, 1), endtime=timedelta(seconds=10))
main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `csp` examples


0 comments on commit 6b90b42

Please sign in to comment.