def test_get_contents_ok(loader): with patch('ansible_runner.loader.open') as mock_open: handler = BytesIO() handler.write(b"test string") handler.seek(0) mock_open.return_value.__enter__.return_value = handler res = loader.get_contents('/tmp') assert res == b'test string'
def test_get_contents_ok(loader, mocker): mock_open = mocker.patch('codecs.open') handler = BytesIO() handler.write(b"test string") handler.seek(0) mock_open.return_value.__enter__.return_value = handler res = loader.get_contents('/tmp') assert res == b'test string'
def test_get_contents_exception(loader): with raises(ConfigurationError): loader.get_contents('/tmp')
def test_get_contents_invalid_path(loader): with raises(ConfigurationError): loader.get_contents('/tmp/invalid')
def test_get_contents_exception(loader, tmp_path): with raises(ConfigurationError): loader.get_contents(tmp_path.as_posix())
def test_get_contents_invalid_path(loader, tmp_path): with raises(ConfigurationError): loader.get_contents(tmp_path.joinpath('invalid').as_posix())