Skip to content

Commit

Permalink
Reduce test strictness.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotwutingfeng committed Nov 8, 2024
1 parent d956a5d commit 53e86bc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 48 deletions.
46 changes: 23 additions & 23 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tomlkit = "^0.13.2"
xlrd = "^2.0.1"

[tool.poetry.group.dev.dependencies]
ruff = "^0.7.2"
ruff = "^0.7.3"
pytest = "^8.3.3"
pytest-cov = "^6.0.0"
pytest-mock = "^3.14.0"
Expand Down
4 changes: 2 additions & 2 deletions railrailrail/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import tomlkit

from railrailrail.coordinates import Coordinates
from railrailrail.network.conditional_transfers import ConditionalTransfers
from railrailrail.network.dwell_time import DwellTime
from railrailrail.network.stage import Stage
Expand All @@ -31,7 +32,6 @@
from railrailrail.network.train_segments import TrainSegments
from railrailrail.network.transfers import Transfers
from railrailrail.network.walks import Walks
from railrailrail.coordinates import Coordinates


class Config:
Expand Down Expand Up @@ -509,7 +509,7 @@ def update_network_config_file(self, path: pathlib.Path) -> None:
updated: list[str] = tomlkit.dumps(network).splitlines()
with open(path, "w") as f:
if original is None or all(not line for line in original):
tomlkit.dump(network, f)
tomlkit.dump(network, f) # File at path is empty or non-existent.
else:
f.write(Config.compare_toml(original, updated))

Expand Down
26 changes: 4 additions & 22 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,33 +232,15 @@ def test_compare_toml(self):
def test_update_network_config_file(self):
config_file_path = pathlib.Path("network_test.toml")

open_calls = [
self.mocker.call(config_file_path, "r"),
self.mocker.call().__enter__(),
self.mocker.call().read(),
self.mocker.call().__exit__(None, None, None),
self.mocker.call(config_file_path, "w"),
self.mocker.call().__enter__(),
self.mocker.call().write(self.mocker.ANY),
self.mocker.call().__exit__(None, None, None),
]
mocked_open = self.mocker.patch(
"railrailrail.config.open", self.mocker.mock_open()
)
) # Overwrite existing file.
self.config_tel_3.update_network_config_file(config_file_path)
mock_calls_without_close = [
c for c in mocked_open.mock_calls if c != self.mocker.call().close()
] # self.mocker.call().close() may not always be called.
if mock_calls_without_close != open_calls:
pytest.fail(f"Expected: {open_calls} \nGot: {mock_calls_without_close}")
assert mocked_open.call_count == 2

open_calls = [
self.mocker.call(config_file_path, "r"),
self.mocker.call(config_file_path, "w"),
]
mocked_open = self.mocker.patch(
"railrailrail.config.open",
side_effect=[OSError, self.mocker.mock_open().return_value],
)
) # Create new file if it is empty or does not exist.
self.config_tel_3.update_network_config_file(config_file_path)
mocked_open.assert_has_calls(open_calls, any_order=False)
assert mocked_open.call_count == 2

0 comments on commit 53e86bc

Please sign in to comment.