Esempio n. 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
Esempio n. 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()
Esempio n. 3
0
def test_abspath_md5_from_file(local_v6_txt, v6_txt_md5_hash):
    u_md5 = AbsPath(local_v6_txt + URIBase.MD5_FILE_EXT)
    if u_md5.exists:
        u_md5.rm()
    assert not u_md5.exists
    u = AbsPath(local_v6_txt)
    assert u.md5_from_file is None

    u.get_metadata(make_md5_file=True)
    assert u_md5.exists
    assert u.md5_from_file == v6_txt_md5_hash
    u_md5.rm()
    assert not u_md5.exists
Esempio n. 4
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
Esempio n. 5
0
def test_abspath_soft_link(local_test_path, local_v6_txt):
    u_src = AbsPath(local_v6_txt)
    f = os.path.join(local_test_path, "test_abspath_soft_link", "v6.txt")
    u_target = AbsPath(f)
    u_target.mkdir_dirname()
    u_src.soft_link(u_target)
    assert u_target.exists and u_target.read() == v6_txt_contents()
    assert u_src.uri == os.path.realpath(u_target.uri)

    with pytest.raises(OSError):
        # file already exists
        u_src.soft_link(u_target)
    # no error if force
    u_src.soft_link(u_target, force=True)
    u_target.rm()
Esempio n. 6
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
Esempio n. 7
0
def test_abspath_get_metadata(local_v6_txt, v6_txt_size, v6_txt_md5_hash):
    u = AbsPath(local_v6_txt)

    m1 = u.get_metadata()
    assert m1.md5 == v6_txt_md5_hash
    assert m1.size == v6_txt_size

    m2 = u.get_metadata(skip_md5=True)
    assert m2.md5 is None
    assert m2.size == v6_txt_size

    u_md5 = AbsPath(local_v6_txt + ".md5")
    if u_md5.exists:
        u_md5.rm()
    m3 = u.get_metadata(make_md5_file=True)
    assert m3.md5 == v6_txt_md5_hash
    assert m3.size == v6_txt_size
    assert u_md5.exists
    assert u_md5.read() == v6_txt_md5_hash