Skip to content

Commit

Permalink
Monkeypatch to stop group events showing up in other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Nov 20, 2024
1 parent 4da331f commit 70f90e2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
27 changes: 25 additions & 2 deletions tests/unit/test_activity_parameter_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@


@bw2test
def test_activity_parameter_revision_expected_format_create(num_revisions):
def test_activity_parameter_revision_expected_format_create(num_revisions, monkeypatch):
def no_signal_save(self, *args, **kwargs):
kwargs["signal"] = False
return super(Group, self).save(*args, **kwargs)

monkeypatch.setattr(Group, "save", no_signal_save)

projects.set_current("activity-event")

assert not ActivityParameter.select().count()
Expand All @@ -27,6 +33,17 @@ def test_activity_parameter_revision_expected_format_create(num_revisions):
amount=5,
data={"foo": "bar"},
)

from pprint import pprint

pprint(
[
json.load(open(fp))
for fp in (projects.dataset.dir / "revisions").iterdir()
if fp.stem.lower() != "head" and fp.is_file()
]
)

assert dp.id > 1e6
assert num_revisions(projects) == 1

Expand Down Expand Up @@ -73,7 +90,13 @@ def test_activity_parameter_revision_expected_format_create(num_revisions):


@bw2test
def test_activity_parameter_revision_apply_create(num_revisions):
def test_activity_parameter_revision_apply_create(num_revisions, monkeypatch):
def no_signal_save(self, *args, **kwargs):
kwargs["signal"] = False
return super(Group, self).save(*args, **kwargs)

monkeypatch.setattr(Group, "save", no_signal_save)

projects.set_current("activity-event")
DatabaseChooser("test-database").register()
assert projects.dataset.revision is None
Expand Down
18 changes: 15 additions & 3 deletions tests/unit/test_database_parameter_events.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import json

from bw2data.database import DatabaseChooser
from bw2data.parameters import DatabaseParameter
from bw2data.parameters import DatabaseParameter, Group
from bw2data.project import projects
from bw2data.snowflake_ids import snowflake_id_generator
from bw2data.tests import bw2test


@bw2test
def test_database_parameter_revision_expected_format_create(num_revisions):
def test_database_parameter_revision_expected_format_create(num_revisions, monkeypatch):
def no_signal_save(self, *args, **kwargs):
kwargs["signal"] = False
return super(Group, self).save(*args, **kwargs)

monkeypatch.setattr(Group, "save", no_signal_save)

projects.set_current("activity-event")

assert not DatabaseParameter.select().count()
Expand Down Expand Up @@ -65,7 +71,13 @@ def test_database_parameter_revision_expected_format_create(num_revisions):


@bw2test
def test_database_parameter_revision_apply_create(num_revisions):
def test_database_parameter_revision_apply_create(num_revisions, monkeypatch):
def no_signal_save(self, *args, **kwargs):
kwargs["signal"] = False
return super(Group, self).save(*args, **kwargs)

monkeypatch.setattr(Group, "save", no_signal_save)

projects.set_current("activity-event")
DatabaseChooser("test-example").register()
assert projects.dataset.revision is None
Expand Down
29 changes: 24 additions & 5 deletions tests/unit/test_project_parameter_events.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import json

from bw2data.database import DatabaseChooser
from bw2data.parameters import ProjectParameter
from bw2data.parameters import Group, ProjectParameter
from bw2data.project import projects
from bw2data.snowflake_ids import snowflake_id_generator
from bw2data.tests import bw2test


@bw2test
def test_project_parameter_revision_expected_format_create(num_revisions):
def test_project_parameter_revision_expected_format_create(num_revisions, monkeypatch):
def no_signal_save(self, *args, **kwargs):
kwargs["signal"] = False
return super(Group, self).save(*args, **kwargs)

monkeypatch.setattr(Group, "save", no_signal_save)

projects.set_current("activity-event")

assert not ProjectParameter.select().count()
Expand Down Expand Up @@ -59,7 +64,13 @@ def test_project_parameter_revision_expected_format_create(num_revisions):


@bw2test
def test_project_parameter_revision_apply_create(num_revisions):
def test_project_parameter_revision_apply_create(num_revisions, monkeypatch):
def no_signal_save(self, *args, **kwargs):
kwargs["signal"] = False
return super(Group, self).save(*args, **kwargs)

monkeypatch.setattr(Group, "save", no_signal_save)

projects.set_current("activity-event")
projects.dataset.set_sourced()
assert projects.dataset.revision is None
Expand Down Expand Up @@ -355,7 +366,15 @@ def fake_recalculate(ignored=None, signal=True):


@bw2test
def test_project_parameter_revision_expected_format_update_formula_parameter_name(num_revisions):
def test_project_parameter_revision_expected_format_update_formula_parameter_name(
num_revisions, monkeypatch
):
def no_signal_save(self, *args, **kwargs):
kwargs["signal"] = False
return super(Group, self).save(*args, **kwargs)

monkeypatch.setattr(Group, "save", no_signal_save)

projects.set_current("activity-event")

assert projects.dataset.revision is None
Expand Down

0 comments on commit 70f90e2

Please sign in to comment.