Skip to content
Snippets Groups Projects

Delivery rework

Merged Daniel Lyons requested to merge delivery-rework into main
7 unresolved threads
Files
2
import filecmp
import pathlib
from os import path
import pytest
from delivery.deliverer import LocalDestination
def test_local_delivery_add_file(tmpdir):
"""Ensure that local delivery does something"""
@pytest.fixture
Please register or sign in to reply
def dest_dir(tmpdir) -> pathlib.Path:
"""
Generate a destination directory.
:param tmpdir: the tmpdir fixture we depend on
:return: path to the destination directory
"""
# generate the destination directory
dest_dir = pathlib.Path(tmpdir) / "after"
dest_dir.mkdir()
return dest_dir
@pytest.fixture
def file_to_deliver(tmpdir) -> pathlib.Path:
"""
Generate some files in a test directory for delivery.
:param tmpdir: pytest fixture for the temporary directory
:return: a file in the test directory
"""
# rewrap the tmpdir as a pathlib.Path instance
tmpdir = pathlib.Path(tmpdir)
# generate the test file in prior
(tmpdir / "prior").mkdir()
file_name = "test.txt"
temp_file = tmpdir.mkdir("prior").join(file_name) # place a file into the source
temp_file = tmpdir / "prior" / file_name # place a file into the source
temp_file.write_text("content", encoding=None) # write something into that file
dest_dir = tmpdir.mkdir("after") # create a destination
# secretly generate a second file
temp_file2 = tmpdir / "prior" / "test2.txt" # make another file in source
temp_file2.write_text("more content", encoding=None) # add some content to the second file
return temp_file
def test_local_delivery_add_file(tmpdir, file_to_deliver: pathlib.Path, dest_dir: pathlib.Path):
"""
Ensure that local delivery works
"""
# generate the destination
local_dest = LocalDestination(None, dest_dir)
local_dest.add_file(temp_file, str(dest_dir / file_name))
# add the file to it
local_dest.add_file(file_to_deliver, file_to_deliver.name)
# see if the source file eneded up in the destination
assert path.exists(dest_dir / file_name)
assert (dest_dir / file_to_deliver.name).exists()
# see if the content of the file is intact
assert (dest_dir / file_name).read_text(encoding=None) == "content"
assert (dest_dir / file_to_deliver.name).read_text(encoding=None) == "content"
def test_local_delivery_add_directory(tmpdir):
def test_local_delivery_add_directory(
tmpdir: pathlib.Path, file_to_deliver: pathlib.Path, dest_dir: pathlib.Path
):
"""Ensure that local delivery does something"""
source_dir = tmpdir.mkdir("prior") # create a source
temp_file = source_dir.join("test.txt") # add a file to the source dir
temp_file.write_text("content", encoding=None) # add some content to the file
temp_file2 = source_dir.join("test2.txt") # make another file in source
temp_file2.write_text("more content", encoding=None) # add some content to the second file
local_dest = LocalDestination(None, str(tmpdir))
local_dest.add_directory(source_dir, "after") # destination is defined here
compare_dirs = filecmp.dircmp(source_dir, tmpdir / "after")
tmpdir = pathlib.Path(tmpdir)
local_dest = LocalDestination(None, dest_dir)
local_dest.add_directory(file_to_deliver.parent, file_to_deliver.parent.name)
compare_dirs = filecmp.dircmp(file_to_deliver.parent, dest_dir / "prior")
# see if the destination got all the files from source
assert (
len(compare_dirs.left_only) == 0
Loading