Exemplo n.º 1
0
def test_storage_encoding(tmpdir, encoding):
    c = Clade(tmpdir, conf={"Storage.convert_to_utf8": True})

    bstr = "мир".encode("cp1251")

    test_file = os.path.join(str(tmpdir), "test")
    with open(test_file, "wb") as fh:
        fh.write(bstr)

    c.add_file_to_storage(test_file, encoding=encoding)
Exemplo n.º 2
0
def test_storage(tmpdir):
    c = Clade(tmpdir)

    returned_storage_path = c.add_file_to_storage(__file__)
    c.add_file_to_storage("do_not_exist.c")

    storage_path = c.get_storage_path(__file__)

    assert storage_path
    assert os.path.exists(storage_path)
    assert storage_path.startswith(c.storage_dir)
    assert returned_storage_path == storage_path

    # Test possible race condition
    with unittest.mock.patch("shutil.copyfile") as copyfile_mock:
        copyfile_mock.side_effect = shutil.SameFileError
        c.add_file_to_storage(test_file)
Exemplo n.º 3
0
def test_storage(tmpdir):
    c = Clade(tmpdir)

    c.add_file_to_storage(__file__)
    c.add_file_to_storage("do_not_exist.c")
    assert os.path.exists(os.path.join(c.storage_dir, __file__))
    assert c.get_storage_path(__file__)

    # Test possible race condition
    with unittest.mock.patch("shutil.copyfile") as copyfile_mock:
        copyfile_mock.side_effect = shutil.SameFileError
        c.add_file_to_storage(test_file)
Exemplo n.º 4
0
def test_storage(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)

    c.add_file_to_storage(__file__)
    assert os.path.exists(os.path.join(c.storage_dir, __file__))
    assert c.get_storage_path(__file__)
Exemplo n.º 5
0
def test_storage_with_conversion(tmpdir):
    c = Clade(tmpdir, conf={"Storage.convert_to_utf8": True})

    with unittest.mock.patch("os.replace") as replace_mock:
        replace_mock.side_effect = OSError
        c.add_file_to_storage(test_file)
Exemplo n.º 6
0
def test_storage_permissions(tmpdir, convert):
    c = Clade(tmpdir, conf={"Storage.convert_to_utf8": convert})
    storage_path = c.add_file_to_storage(__file__)
    assert os.stat(storage_path)[stat.ST_MODE] == os.stat(__file__)[
        stat.ST_MODE]