aboutsummaryrefslogtreecommitdiff
path: root/tests/test_config.py
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-03-06 10:13:17 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-03-06 10:13:17 +0100
commit2a854b36624fb1c108a56d317aa54ca630864288 (patch)
treee50a5f2c2f77966c60580bdc1e73ce66be7b66b5 /tests/test_config.py
parent422c56fbc5cd7493aaa96a341ebfff077f7a7de3 (diff)
downloadminishell_test-2a854b36624fb1c108a56d317aa54ca630864288.tar.gz
minishell_test-2a854b36624fb1c108a56d317aa54ca630864288.tar.bz2
minishell_test-2a854b36624fb1c108a56d317aa54ca630864288.zip
Updated tests to use monkeypatch.setattr(Config, attr, value) instead of custom config_context
Diffstat (limited to 'tests/test_config.py')
-rw-r--r--tests/test_config.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index b0a9142..deb9761 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -6,7 +6,7 @@
# By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/03/03 12:25:29 by cacharle #+# #+# #
-# Updated: 2021/03/03 16:27:07 by cacharle ### ########.fr #
+# Updated: 2021/03/06 10:11:30 by cacharle ### ########.fr #
# #
# ############################################################################ #
@@ -169,26 +169,25 @@ class TestConfig:
Config.init(["--range", "1", "100"])
assert Config.show_range
- def test_init_valgrind_not_found(self):
- prev = distutils.spawn.find_executable
- distutils.spawn.find_executable = lambda _: None # noqa
+ def test_init_valgrind_not_found(self, monkeypatch):
+ monkeypatch.setattr(distutils.spawn, "find_executable", lambda _: None)
with pytest.raises(ConfigSetupException) as e:
Config.init(["--check-leaks"])
- distutils.spawn.find_executable = prev
assert "Could not find the valgrind command on your system" == e.value.__str__()
- def test_init_term_cols_too_low(self):
- prev = shutil.get_terminal_size
- shutil.get_terminal_size = lambda: os.terminal_size((39, 80)) # noqa
+ def test_init_term_cols_too_low(self, monkeypatch):
+ def mock_get_terminal_size(fallback=None):
+ # has to support fallback since pytest uses this function during the verbose test
+ if fallback is not None:
+ return os.terminal_size(fallback)
+ return os.terminal_size((39, 80))
+ monkeypatch.setattr(shutil, "get_terminal_size", mock_get_terminal_size)
with pytest.raises(ConfigSetupException) as e:
Config.init(["--check-leaks"])
- shutil.get_terminal_size = prev
assert "You're terminal isn't wide enough 40 cols minimum required" == e.value.__str__()
- def test_platform_not_supported(self):
- prev = sys.platform
- sys.platform = 'windows'
+ def test_platform_not_supported(self, monkeypatch):
+ monkeypatch.setattr(sys, "platform", "windows")
with pytest.raises(ConfigSetupException) as e:
Config.init(["--check-leaks"])
- sys.platform = prev
assert "Your platform (windows) is not supported, supported platforms are: linux, darwin" == e.value.__str__()