Skip to content

Commit

Permalink
Merge 9c933de into 39e78ad
Browse files Browse the repository at this point in the history
  • Loading branch information
Bachibouzouk committed May 19, 2020
2 parents 39e78ad + 9c933de commit eebe668
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 25 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ after_success:
- coveralls

env:
- COVERALLS_REPO_TOKEN=${{ secrets.coverage_token }}
- EXECUTE_TESTS_ON=skip

jobs:
exlude:
- if: branch IN (master)
env: COVERALLS_REPO_TOKEN=${{ secrets.coverage_token }} EXECUTE_TESTS_ON=master
- if: branch IN (dev)
env: COVERALLS_REPO_TOKEN=${{ secrets.coverage_token }} EXECUTE_TESTS_ON=dev

# - pylint */*.py
#jobs:
# include:
Expand Down
20 changes: 16 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ python setup.py develop
```
Otherwise your changes will not be perceived by the tests unless you run `python setup.py install` each time.

```bash
pip install -e .
```
should work as well.

Please run the tests locally before pushing your feature to the developer branch. You do that by running:
```bash
pytest
Expand All @@ -67,12 +72,19 @@ If a test fails, it is only due to what you changed (the test must passed before
test names and error messages are there to help you find the error, please read them to try to
debug yourself before seeking assistance :)

Some test take more time to run (run a simulation) and were therefore disabled by default. it is
nevertheless important that you run a simulation test before you ask a review, to make sure the
code still works
Some test take more time to run (run a simulation) and were therefore disabled by default. It is
nevertheless important that you run a simulation test before you ask a review, or whenever you
are ready to merge, to make sure the
code still works.
```bash
pytest tests/test_benchmark.py
EXECUTE_TESTS_ON=dev pytest
```
will execute only the main simulation once to make sure it runs smoothly, whereas
```bash
EXECUTE_TESTS_ON=master pytest
```
will execute *all* benchmark tests (it takes thus a longer time to run)


#### Step 4: Submit a pull request (PR)

Expand Down
8 changes: 8 additions & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# import constants from src
from src.constants import (
INPUT_FOLDER,
OUTPUT_FOLDER,
DEFAULT_INPUT_PATH,
DEFAULT_OUTPUT_PATH,
JSON_FNAME,
JSON_EXT,
CSV_ELEMENTS,
Expand All @@ -16,6 +19,11 @@
DICT_PLOTS,
)

TESTS_ON_MASTER = "master"
TESTS_ON_DEV = "dev"

EXECUTE_TESTS_ON = os.environ.get("EXECUTE_TESTS_ON", "skip")

TEST_REPO_PATH = os.path.dirname(__file__)

DUMMY_CSV_PATH = os.path.join(TEST_REPO_PATH, "test_data")
Expand Down
19 changes: 11 additions & 8 deletions tests/test_A0_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

import src.A0_initialization as initializing

from src.constants import (
REPO_PATH,
from .constants import (
EXECUTE_TESTS_ON,
TESTS_ON_MASTER,
TEST_REPO_PATH,
CSV_ELEMENTS,
INPUTS_COPY,
INPUT_FOLDER,
OUTPUT_FOLDER,
JSON_FNAME,
JSON_PATH,
JSON_EXT,
CSV_FNAME,
CSV_EXT,
Expand Down Expand Up @@ -187,14 +188,14 @@ def test_check_input_path_posix():
"""Verify the code works on both windows and linux path systems"""
if os.name == "posix":
folder = initializing.check_input_folder(
"{}/tests/inputs/".format(REPO_PATH), JSON_EXT
"{}/inputs/".format(TEST_REPO_PATH), JSON_EXT
)
else:
folder = initializing.check_input_folder(
"{}\\tests\\inputs\\".format(REPO_PATH), JSON_EXT
"{}\\inputs\\".format(TEST_REPO_PATH), JSON_EXT
)

assert folder == os.path.join(REPO_PATH, "tests", "inputs", JSON_FNAME)
assert folder == os.path.join(JSON_PATH)


TEST_OUTPUT_PATH = os.path.join(".", "tests", "other")
Expand Down Expand Up @@ -269,7 +270,9 @@ def test_log_not_accepting_other_choices(self):
# this ensure that the test is only ran if explicitly executed,
# ie not when the `pytest` command alone it called
@pytest.mark.skipif(
"tests/test_A0_initialization.py" not in sys.argv, reason="requires python3.3"
EXECUTE_TESTS_ON not in (TESTS_ON_MASTER),
reason="Benchmark test deactivated, set env variable "
"EXECUTE_TESTS_ON to 'master' to run this test",
)
@mock.patch(
"argparse.ArgumentParser.parse_args",
Expand Down
13 changes: 10 additions & 3 deletions tests/test_F0_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
import src.B0_data_input_json as B0
import src.F0_output as F0

from .constants import TEST_REPO_PATH, DICT_PLOTS, PDF_REPORT
from .constants import (
EXECUTE_TESTS_ON,
TESTS_ON_MASTER,
TEST_REPO_PATH,
DICT_PLOTS,
PDF_REPORT,
)
from mvs_eland_tool.mvs_eland_tool import main
import src.A0_initialization as initializing

Expand Down Expand Up @@ -184,8 +190,9 @@ def test_store_dict_into_json(self):
assert os.path.exists(os.path.join(OUTPUT_PATH, file_name + ".json")) is True

@pytest.mark.skipif(
"tests/{}".format(os.path.basename(__file__)) not in sys.argv,
reason="lengthy test",
EXECUTE_TESTS_ON not in (TESTS_ON_MASTER),
reason="Benchmark test deactivated, set env variable "
"EXECUTE_TESTS_ON to 'master' to run this test",
)
@mock.patch(
"argparse.ArgumentParser.parse_args",
Expand Down
15 changes: 14 additions & 1 deletion tests/test_F1_plotting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shutil
import pytest
import mock
import pandas as pd
import logging
Expand All @@ -8,7 +9,9 @@
import src.A0_initialization as initializing

import src.F1_plotting as F1
from tests.constants import (
from .constants import (
EXECUTE_TESTS_ON,
TESTS_ON_MASTER,
TEST_REPO_PATH,
DUMMY_CSV_PATH,
INPUT_FOLDER,
Expand Down Expand Up @@ -78,6 +81,11 @@ def setup_class(self):
""" """
shutil.rmtree(TEST_OUTPUT_PATH, ignore_errors=True)

@pytest.mark.skipif(
EXECUTE_TESTS_ON not in (TESTS_ON_MASTER),
reason="Benchmark test deactivated, set env variable "
"EXECUTE_TESTS_ON to 'master' to run this test",
)
@mock.patch(
"argparse.ArgumentParser.parse_args",
return_value=PARSER.parse_args(
Expand All @@ -90,6 +98,11 @@ def test_if_networkx_graph_is_stored_save_plot_true(self, m_args):
os.path.exists(os.path.join(TEST_OUTPUT_PATH, "network_graph.png")) is True
)

@pytest.mark.skipif(
EXECUTE_TESTS_ON not in (TESTS_ON_MASTER),
reason="Benchmark test deactivated, set env variable "
"EXECUTE_TESTS_ON to 'master' to run this test",
)
@mock.patch(
"argparse.ArgumentParser.parse_args",
return_value=PARSER.parse_args(
Expand Down
18 changes: 14 additions & 4 deletions tests/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
import mock
import pytest

from .constants import TEST_REPO_PATH, JSON_EXT, CSV_EXT
from .constants import (
EXECUTE_TESTS_ON,
TESTS_ON_MASTER,
TESTS_ON_DEV,
TEST_REPO_PATH,
JSON_EXT,
CSV_EXT,
)
from mvs_eland_tool.mvs_eland_tool import main


OUTPUT_PATH = os.path.join(TEST_REPO_PATH, "MVS_outputs_simulation")
fname = os.path.basename(__file__)


class TestSimulation:
Expand All @@ -27,7 +33,9 @@ def setup_method(self):
# this ensure that the test is only ran if explicitly executed, ie not when the `pytest` command
# alone it called
@pytest.mark.skipif(
"tests/{}".format(fname) not in sys.argv, reason="requires python3.3"
EXECUTE_TESTS_ON not in (TESTS_ON_MASTER, TESTS_ON_DEV),
reason="Benchmark test deactivated, set env variable "
"EXECUTE_TESTS_ON to 'master' to run this test",
)
@mock.patch("argparse.ArgumentParser.parse_args", return_value=argparse.Namespace())
def test_run_smoothly_json(self, mock_args):
Expand All @@ -37,7 +45,9 @@ def test_run_smoothly_json(self, mock_args):
assert 1 == 1

@pytest.mark.skipif(
"tests/{}".format(fname) not in sys.argv, reason="requires python3.3"
EXECUTE_TESTS_ON not in (TESTS_ON_MASTER),
reason="Benchmark test deactivated, set env variable "
"EXECUTE_TESTS_ON to 'master' to run this test",
)
@mock.patch("argparse.ArgumentParser.parse_args", return_value=argparse.Namespace())
def test_run_smoothly_csv(self, mock_args):
Expand Down
17 changes: 13 additions & 4 deletions tests/test_benchmark_simple_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
import pytest
import pandas as pd

from .constants import TEST_REPO_PATH, JSON_EXT, CSV_EXT
from .constants import (
EXECUTE_TESTS_ON,
TESTS_ON_MASTER,
TEST_REPO_PATH,
JSON_EXT,
CSV_EXT,
)
from mvs_eland_tool.mvs_eland_tool import main

TEST_INPUT_PATH = os.path.join(TEST_REPO_PATH, "benchmark_test_inputs")
TEST_OUTPUT_PATH = os.path.join(TEST_REPO_PATH, "benchmark_test_outputs")
fname = os.path.basename(__file__)


class TestACElectricityBus:
Expand All @@ -29,7 +34,9 @@ def setup_method(self):
# this ensure that the test is only ran if explicitly executed, ie not when the `pytest` command
# alone is called
@pytest.mark.skipif(
"tests/{}".format(fname) not in sys.argv, reason="requires python3.3"
EXECUTE_TESTS_ON not in (TESTS_ON_MASTER),
reason="Benchmark test deactivated, set env variable "
"EXECUTE_TESTS_ON to 'master' to run this test",
)
@mock.patch("argparse.ArgumentParser.parse_args", return_value=argparse.Namespace())
def test_benchmark_AB_grid_pv(self, margs):
Expand All @@ -55,7 +62,9 @@ def test_benchmark_AB_grid_pv(self, margs):
# this ensure that the test is only ran if explicitly executed, ie not when the `pytest` command
# alone is called
@pytest.mark.skipif(
"tests/{}".format(fname) not in sys.argv, reason="requires python3.3"
EXECUTE_TESTS_ON not in (TESTS_ON_MASTER),
reason="Benchmark test deactivated, set env variable "
"EXECUTE_TESTS_ON to 'master' to run this test",
)
@mock.patch("argparse.ArgumentParser.parse_args", return_value=argparse.Namespace())
def test_benchmark_AE_grid_battery(self, margs):
Expand Down

0 comments on commit eebe668

Please sign in to comment.