-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from mariuzka/dev
Dev
- Loading branch information
Showing
3 changed files
with
59 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import warnings | ||
|
||
import networkx as nx | ||
import pytest | ||
|
||
import pop2net as p2n | ||
|
||
|
||
def test_enable_warnings_true(): | ||
model = p2n.Model(enable_p2n_warnings=True) | ||
creator = p2n.Creator(model) | ||
|
||
class LineLocation(p2n.MagicLocation): | ||
nxgraph = nx.path_graph(10) | ||
n_agents = 10 | ||
|
||
creator.create_agents(n=10) | ||
|
||
with pytest.warns(UserWarning) as record: | ||
creator.create_locations( | ||
location_classes=[LineLocation], | ||
delete_magic_agent_attributes=False, | ||
) | ||
assert len(record) > 0, "Expected a warning but none were raised." | ||
|
||
|
||
def test_enable_warnings_false(): | ||
model = p2n.Model(enable_p2n_warnings=False) | ||
creator = p2n.Creator(model) | ||
|
||
class LineLocation(p2n.MagicLocation): | ||
nxgraph = nx.path_graph(10) | ||
n_agents = 10 | ||
|
||
creator.create_agents(n=10) | ||
|
||
with warnings.catch_warnings(record=True) as record: | ||
warnings.simplefilter("always") | ||
creator.create_locations( | ||
location_classes=[LineLocation], | ||
delete_magic_agent_attributes=False, | ||
) | ||
assert len(record) == 0, "Expected no warnings but warnings were raised." |