-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
5 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,4 +1,4 @@ | ||
sonar.projectKey=Laerdal_python-objdictgen | ||
sonar.organization=laerdal-foss | ||
sonar.python.coverage.reportPaths=coverage.xml | ||
sonar.exclusions = tests/** | ||
sonar.exclusions = tests/**, packaging/** |
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,38 @@ | ||
|
||
import pytest | ||
from unittest import mock | ||
import os | ||
import sys | ||
|
||
@pytest.fixture | ||
def setenvvar(monkeypatch): | ||
with mock.patch.dict(os.environ, {"TEST": "foobar"}): | ||
yield | ||
|
||
|
||
def test_filereplacer(basepath, wd, setenvvar): | ||
|
||
sys.path.append(str(basepath / "packaging")) | ||
os.chdir(basepath) | ||
from filereplacer import convert | ||
|
||
tests = [ | ||
(1, "Test data", "Test data"), | ||
(2, "@@{name}", "objdictgen"), | ||
(3, "@@{TEST}", "foobar"), # Read from the mocked environment variable | ||
(4, "@@{nonexisting}", "non-existing"), | ||
] | ||
|
||
for i, data, result in tests: | ||
infile = wd / "test.txt" | ||
outfile = wd / "out.txt" | ||
with open(infile, "w", encoding="utf-8") as f: | ||
f.write(data) | ||
if i == 4: | ||
with pytest.raises(KeyError): | ||
convert(infile, outfile) | ||
continue | ||
else: | ||
convert(infile, outfile) | ||
with open(outfile, "r", encoding="utf-8") as f: | ||
assert f.read() == result |