Skip to content

Commit

Permalink
App context already pushed by test fixture (FlexMeasures#600)
Browse files Browse the repository at this point in the history
The app fixture in flexmeasures/conftest.py already pushes the app context, so there is no need to set it up again in tests that already use this fixture.


* Remove redundant app_context statement

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Correct capitalization

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Flix6x committed Mar 7, 2023
1 parent 99d77bd commit 1669b0e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
6 changes: 3 additions & 3 deletions documentation/dev/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Using a virtual environment is best practice for Python developers. We also stro
an `Anaconda distribution <https://conda.io/docs/user-guide/tasks/manage-environments.html>`_ as base with ``conda create -n flexmeasures-venv python=3.10``.
* Activate it, e.g.: ``source flexmeasures-venv/bin/activate``

Download Flexmeasures
Download FlexMeasures
^^^^^^^^^^^^^^^^^^^^^^^
Clone the `Flexmeasures repository <https://github.com/FlexMeasures/flexmeasures.git>`_ from Github.
Clone the `FlexMeasures repository <https://github.com/FlexMeasures/flexmeasures.git>`_ from GitHub.

.. code-block:: console
Expand Down Expand Up @@ -168,7 +168,7 @@ in your virtual environment.
Now each git commit will first run ``flake8``, then ``black`` and finally ``mypy`` over the files affected by the commit
(\ ``pre-commit`` will install these tools into its own structure on the first run).

This is also what happens automatically server-side when code is committed to a branch (via Github Actions), but having those tests locally as well will help you spot these issues faster.
This is also what happens automatically server-side when code is committed to a branch (via GitHub Actions), but having those tests locally as well will help you spot these issues faster.

If ``flake8``, ``black`` or ``mypy`` propose changes to any file, the commit is aborted (saying that it "failed").
The changes proposed by ``black`` are implemented automatically (you can review them with `git diff`). Some of them might even resolve the ``flake8`` warnings :)
Expand Down
38 changes: 17 additions & 21 deletions flexmeasures/utils/tests/test_entity_address_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,15 @@
def test_build_entity_address(
app, info: dict, entity_type: str, host: str, fm_scheme: str, exp_result: str
):
with app.app_context():
app.config["FLEXMEASURES_HOSTS_AND_AUTH_START"] = {
"flexmeasures.io": "2021-01",
"staging.flexmeasures.io": "2022-09",
}
if exp_result.startswith("ea1"):
assert (
build_entity_address(info, entity_type, host, fm_scheme) == exp_result
)
else:
with pytest.raises(EntityAddressException, match=exp_result):
build_entity_address(info, entity_type, host, fm_scheme) == exp_result
app.config["FLEXMEASURES_HOSTS_AND_AUTH_START"] = {
"flexmeasures.io": "2021-01",
"staging.flexmeasures.io": "2022-09",
}
if exp_result.startswith("ea1"):
assert build_entity_address(info, entity_type, host, fm_scheme) == exp_result
else:
with pytest.raises(EntityAddressException, match=exp_result):
build_entity_address(info, entity_type, host, fm_scheme) == exp_result


@pytest.mark.parametrize(
Expand Down Expand Up @@ -253,15 +250,14 @@ def test_build_ea_scheme_and_naming_authority(app):
build_ea_scheme_and_naming_authority("flexmeasures.io")
== "ea1.2021-01.io.flexmeasures"
)
with app.app_context():
app.config["FLEXMEASURES_HOSTS_AND_AUTH_START"] = {
"flexmeasures.io": "2021-01",
"company.flexmeasures.io": "2020-04",
}
assert (
build_ea_scheme_and_naming_authority("company.flexmeasures.io")
== "ea1.2020-04.io.flexmeasures.company"
)
app.config["FLEXMEASURES_HOSTS_AND_AUTH_START"] = {
"flexmeasures.io": "2021-01",
"company.flexmeasures.io": "2020-04",
}
assert (
build_ea_scheme_and_naming_authority("company.flexmeasures.io")
== "ea1.2020-04.io.flexmeasures.company"
)
assert (
build_ea_scheme_and_naming_authority("company.flexmeasures.io", "1999-12")
== "ea1.1999-12.io.flexmeasures.company"
Expand Down

0 comments on commit 1669b0e

Please sign in to comment.