First test and mocking attempt

This commit is contained in:
Juergen Edelbluth 2018-08-18 20:35:33 +02:00
parent 228364e1fb
commit 7b0545ffd3
4 changed files with 25 additions and 0 deletions

2
.gitignore vendored
View File

@ -166,3 +166,5 @@ fabric.properties
[Ss]cripts
pyvenv.cfg
pip-selfcheck.json
.pytest_cache/

View File

@ -0,0 +1,2 @@
pytest>=3.7.2,<3.8
pytest-mock>=1.10.0,<1.11

0
src/test/__init__.py Normal file
View File

View File

@ -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')