예제 #1
0
def test_files_exists(monkeypatch):
    with mock.patch("socket.gethostbyname", return_value="127.0.0.1"):
        files = Files()
    def always_true(_):
        return True
    def always_false(_):
        return False
    monkeypatch.setattr(files.redis, "exists", always_false)
    assert files.exists("path") == False
    monkeypatch.delattr(files.redis, "exists")
    monkeypatch.setattr(files.redis, "exists", always_true)
    assert files.exists("path") == True
예제 #2
0
def test_files_exists_bad_path(monkeypatch):
    with mock.patch("socket.gethostbyname", return_value="127.0.0.1"):
        files = Files()
    error_message = "path argument must be a non empty string"
    with pytest.raises(ValueError, match=error_message):
        files.exists(None)
    with pytest.raises(ValueError, match=error_message):
        files.exists("")
    with pytest.raises(ValueError, match=error_message):
        files.exists({"a": 0})
    with pytest.raises(ValueError, match=error_message):
        files.exists([])