From 7cf099850c7fca9d1d91bdc30e3c662ea522bfb5 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Thu, 19 Dec 2024 13:28:52 +0100 Subject: [PATCH] Add testing information to readme (#10) * Add testing information to readme * Refactor readme * Example usage in readme * Update README.md Co-authored-by: PiotrJunior <37268347+PiotrJunior@users.noreply.github.com> * fixes from PR comments --------- Co-authored-by: Tomasz Kwiatkowski <41270545+geoff128@users.noreply.github.com> Co-authored-by: PiotrJunior <37268347+PiotrJunior@users.noreply.github.com> Co-authored-by: jrozek --- .gitignore | 4 ++ README.md | 80 ++++++++++++++++++++++++++++++++++ src/sio3pack/graph/graph_op.py | 4 +- 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 471c6cc..36815e6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,11 @@ build .idea __pycache__ tests/test_django/db.sqlite3 +htmlcov # pytest-cov .coverage* coverage.xml + +# macOS +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 26ffe42..5489e1a 100644 --- a/README.md +++ b/README.md @@ -1 +1,81 @@ +from sio3pack.graph import GraphOperation + # SIO3Pack + +## Example usage + +### In OIOIOI + +```python +# Package unpacking +import sio3pack, sio3workers +from django.conf import settings +package = sio3pack.from_file(path_to_package, django_settings=settings) +graph_op: GraphOperation = package.get_unpack_graph() +results = sioworkers.run(graph_op) +graph_op.return_results(results) +package.save_to_db(problem_id=1) +``` + +### Locally (for example `sinol-make`) + +```python +import sio3pack, sio3workers.local +package = sio3pack.from_file(path_to_package) +graph_op: GraphOperation = package.get_unpack_graph() +results = sio3workers.local.run(graph_op) +graph_op.return_results(results) +``` + +--- + +## Development + +### Test without django support + +Install the package in editable mode and make sure that `django` and +`pytest-django` are not installed. + +```bash +pip install -e ".[tests]" +pip uninstall django pytest-django +``` + +Then follow the instructions in +[General testing information](#general-testing-information). + + +### Test with django support + +Install the package in editable mode along with Django dependencies: + +```bash +pip install -e ".[django,tests,django_tests]" +``` + +Then follow the instructions in +[General testing information](#general-testing-information). + + +### General testing information + +Run the tests with `pytest` in the root directory of +the repository. + +```bash +pytest -v +``` + +To run tests in parallel, use the following command. + +```bash +pytest -v -n auto +``` + +To run coverage tests, use the following command. + +```bash +pytest -v --cov=sio3pack --cov-report=html +``` + +The coverage report will be generated in the file `htmlcov/index.html`. diff --git a/src/sio3pack/graph/graph_op.py b/src/sio3pack/graph/graph_op.py index f5d4994..3ef4257 100644 --- a/src/sio3pack/graph/graph_op.py +++ b/src/sio3pack/graph/graph_op.py @@ -15,9 +15,9 @@ def __init__(self, graph: Graph, return_results: bool = False, return_func: call results, if return_results is True. """ self.graph = graph - self.return_results = return_results + self.should_return = return_results self.return_func = return_func def return_results(self, data: dict): - if self.return_func: + if self.return_func and self.should_return: return self.return_func(data)