Skip to content

Commit

Permalink
test deletion of magic agent attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuzka committed Oct 22, 2024
1 parent 30f3807 commit 0fac6dd
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions tests/test_creator/test_creator_delete_magic_attrs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import pandas as pd

import pop2net as p2n

magic_agent_attributes = ["", "_assigned", "_id", "_position", "_head", "_tail"]
magic_agent_attributes = ["Location1" + attr for attr in magic_agent_attributes] + [
"Location2" + attr for attr in magic_agent_attributes
]


def test_del_magic_agent_attrs1():
model = p2n.Model()
creator = p2n.Creator(model=model)

class Location1(p2n.MagicLocation):
pass

class Location2(p2n.MagicLocation):
pass

# First test: Do NOT delete magic agent attributes
creator.create_agents(n=10)
creator.create_locations(
location_classes=[Location1, Location2],
delete_magic_agent_attributes=False,
)

for agent in model.agents:
for attr in magic_agent_attributes:
assert hasattr(agent, attr)

# Second test: DELETE magic agent attributes
creator.create_agents(n=10, clear=True)
creator.create_locations(
location_classes=[Location1, Location2],
delete_magic_agent_attributes=True,
clear=True,
)

for agent in model.agents:
for attr in magic_agent_attributes:
assert not hasattr(agent, attr)


def test_del_magic_agent_attrs2():
df = pd.DataFrame({"testattr": [10, 11, 12, 13]})

model = p2n.Model()
creator = p2n.Creator(model=model)

class Location1(p2n.MagicLocation):
pass

class Location2(p2n.MagicLocation):
pass

# First test: Do NOT delete magic agent attributes
creator.create(
df=df,
n_agents=10,
location_classes=[Location1, Location2],
delete_magic_agent_attributes=False,
)

for agent in model.agents:
for attr in magic_agent_attributes:
assert hasattr(agent, attr)

# Second test: DELETE magic agent attributes
creator.create(
df=df,
n_agents=10,
location_classes=[Location1, Location2],
delete_magic_agent_attributes=True,
clear=True,
)

for agent in model.agents:
for attr in magic_agent_attributes:
assert not hasattr(agent, attr)

0 comments on commit 0fac6dd

Please sign in to comment.