Skip to content

Commit

Permalink
Finalized the test for duplicate reaction names.
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-drews committed Sep 16, 2024
1 parent 73c465b commit 69525bc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/acom_music_box/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ def main():
myBox = MusicBox()
logger.debug(f"Configuration file = {musicBoxConfigFile}")
myBox.readConditionsFromJson(musicBoxConfigFile)
myBox.check_config(os.path.join(os.getcwd(), musicBoxConfigFile))

# Create solver and solve
config_path = os.path.join(
os.path.dirname(musicBoxConfigFile),
myBox.config_file)
myBox.create_solver(config_path)
myBox.check_config(config_path)
result = myBox.solve(musicBoxOutputPath)

if musicBoxOutputPath is None:
Expand Down
6 changes: 3 additions & 3 deletions src/acom_music_box/music_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def create_solver(

def check_config(self, boxConfigPath):
"""
Verifies correct configuration of the solver object.
Verifies correct configuration of the MusicBox object.
There is intentionally no check for the presence of a solver;
this test function is for the loaded configuration only.
Args:
boxConfigPath = filename and path of MusicBox configuration file
Expand All @@ -102,8 +104,6 @@ def check_config(self, boxConfigPath):
True if all checks passed
Throws error for the first check failed.
"""
if (not self.solver):
return(False)

# look for duplicate reaction names
if (self.initial_conditions):
Expand Down
18 changes: 16 additions & 2 deletions tests/integration/test_duplicate_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,26 @@ def test_run(self):
abc789 = ReactionRate(Reaction("abc"), 78.9)

# Pass: unique reaction names
pass_reactions = ReactionList(name="Pass list", reactions=[abc123, def456])
pass_reactions = [abc123, def456]
pass_conditions = Conditions(reaction_rates=pass_reactions)
box_model = MusicBox(initial_conditions=pass_conditions)
box_model.check_config("Loaded from string.")

assert True, f"All is good."
# Pass test should throw an error above if it fails
assert True, f"All is good." # example of assertion

# Fail: duplicate reaction names
fail_reactions = reactions=[abc123, abc789]
fail_conditions = Conditions(reaction_rates=fail_reactions)
box_model = MusicBox(initial_conditions=fail_conditions) # new instance

# catching the exception is a Pass for the duplicate case
caughtExcept = False
try:
box_model.check_config("Loaded from string.")
except Exception as myExcept:
caughtExcept = True
assert caughtExcept, f"Failed to detect duplicate reaction names."


if __name__ == "__main__":
Expand Down

0 comments on commit 69525bc

Please sign in to comment.