diff --git a/.gitignore b/.gitignore index 46941b3..345e569 100644 --- a/.gitignore +++ b/.gitignore @@ -166,3 +166,5 @@ fabric.properties [Ss]cripts pyvenv.cfg pip-selfcheck.json + +.pytest_cache/ \ No newline at end of file diff --git a/src/requirements-test.txt b/src/requirements-test.txt new file mode 100644 index 0000000..3d0cd4c --- /dev/null +++ b/src/requirements-test.txt @@ -0,0 +1,2 @@ +pytest>=3.7.2,<3.8 +pytest-mock>=1.10.0,<1.11 diff --git a/src/test/__init__.py b/src/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/test/test_configuration_file_discovery.py b/src/test/test_configuration_file_discovery.py new file mode 100644 index 0000000..d8d3fe9 --- /dev/null +++ b/src/test/test_configuration_file_discovery.py @@ -0,0 +1,21 @@ +import os + +import pytest +from _pytest.monkeypatch import MonkeyPatch + +from rs500common.configuration import discover_config_file_by_name + + +def test_discovery(monkeypatch: MonkeyPatch): + def mock(path): + return True + with monkeypatch.context() as m: + m.setattr(os.path, 'isfile', mock) + m.setattr(os.path, 'exists', mock) + result = discover_config_file_by_name('test.ini', '/foo/bar') + assert result == os.path.join('/foo/bar', 'test.ini') + + +def test_no_hit(): + with pytest.raises(FileNotFoundError): + discover_config_file_by_name('does-not-exist.nothing', 'bla-blubb')