Beispiel #1
0
def test_abspath_mtime(local_v6_txt):
    u = AbsPath(local_v6_txt + ".tmp")
    u.write("temp file for testing")
    now = time.time()
    assert now - 10 < u.mtime < now + 10
    u.rm()
    assert not u.exists
Beispiel #2
0
def test_abspath_get_abspath_if_exists():
    # write a local file on CWD.
    test_local_file_abspath = os.path.join(os.getcwd(), "test.txt")
    u = AbsPath(test_local_file_abspath)
    if u.exists:
        u.rm()

    # if it doesn't exist
    assert AbsPath.get_abspath_if_exists("test.txt") == "test.txt"
    assert AbsPath.get_abspath_if_exists(AutoURI("test.txt")) == "test.txt"

    u.write("hello-world")

    # if it exists
    assert AbsPath.get_abspath_if_exists("test.txt") == test_local_file_abspath
    assert AbsPath.get_abspath_if_exists(
        AutoURI("test.txt")) == test_local_file_abspath

    assert AbsPath.get_abspath_if_exists(
        "tttttttttest.txt") == "tttttttttest.txt"
    assert (AbsPath.get_abspath_if_exists(
        AutoURI("tttttttttest.txt")) == "tttttttttest.txt")
    assert (AbsPath.get_abspath_if_exists("~/if-it-does-not-exist") ==
            "~/if-it-does-not-exist")
    assert AbsPath.get_abspath_if_exists(
        "non-existing-file") == "non-existing-file"

    u.rm()
Beispiel #3
0
def test_abspath_write(local_test_path):
    u = AbsPath(local_test_path + "/test_abspath_write.tmp")

    assert not u.exists
    u.write("test")
    assert u.exists and u.read() == "test"
    u.rm()

    # this will be tested more with multiple threads in test_race_cond.py
    assert not u.exists
    u.write("test2", no_lock=True)
    assert u.exists and u.read() == "test2"
    u.rm()
    assert not u.exists
Beispiel #4
0
def test_abspath_rm(local_test_path):
    u = AbsPath(local_test_path + "/test_abspath_rm.tmp")

    assert not u.exists
    u.write("")
    assert u.exists
    u.rm()
    assert not u.exists

    # this will be tested more with multiple threads in test_race_cond.py
    assert not u.exists
    u.write("", no_lock=True)
    assert u.exists
    u.rm()
    assert not u.exists
Beispiel #5
0
def test_abspath_write_no_permission():
    u = AbsPath("/test-permission-denied/x.tmp")
    with pytest.raises(PermissionError):
        u.write("test")