-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
93 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import pathlib | ||
import sys | ||
import venv | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def executable(): | ||
"""Return the current interpreter's path.""" | ||
return pathlib.Path(sys.executable) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def full_venv(tmp_path_factory): | ||
"""Create a virtual environment via venv.""" | ||
venv_path = tmp_path_factory.mktemp("venvs") / "full_venv" | ||
venv.create(venv_path, symlinks=True, with_pip=False, system_site_packages=False) | ||
return venv_path |
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,46 @@ | ||
import contextlib | ||
|
||
import pytest | ||
|
||
import microvenv | ||
|
||
|
||
@contextlib.contextmanager | ||
def write_config(venv_path, data): | ||
"""Context manager to write the pyvenv.cfg and then restore it.""" | ||
config_path = venv_path / "pyvenv.cfg" | ||
original_config = config_path.read_text(encoding="utf-8") | ||
config_path.write_text(data, encoding="utf-8") | ||
try: | ||
yield config_path | ||
finally: | ||
config_path.write_text(original_config, encoding="utf-8") | ||
|
||
|
||
@pytest.mark.parametrize("equals", ["=", " = ", "= ", " ="]) | ||
def test_formatting_around_equals(full_venv, equals): | ||
with write_config(full_venv, f"key{equals}value\n"): | ||
config = microvenv.parse_config(full_venv) | ||
|
||
assert config["key"] == "value" | ||
|
||
|
||
def test_comments(full_venv): | ||
with write_config(full_venv, "# A comment\nkey = value\n"): | ||
config = microvenv.parse_config(full_venv) | ||
|
||
assert config["key"] == "value" | ||
|
||
|
||
def test_multiple_equals(full_venv): | ||
with write_config(full_venv, "key = value=value\n"): | ||
config = microvenv.parse_config(full_venv) | ||
|
||
assert config["key"] == "value=value" | ||
|
||
|
||
def test_lowercase_keys(full_venv): | ||
with write_config(full_venv, "Key = value\n"): | ||
config = microvenv.parse_config(full_venv) | ||
|
||
assert config["key"] == "value" |