Antilint
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Olivier 'reivilibre' 2021-07-20 11:02:13 +01:00
parent 0e908aa582
commit d3345ea30a
8 changed files with 84 additions and 38 deletions

View File

@ -33,6 +33,16 @@ class TestBackupAndExtract(TestCase):
print("extracting")
dest_path = tdpath.joinpath("desta")
subprocess.check_call(("datman", "extract", "--skip-metadata", "--accept-partial", "main", "../desta"), cwd=datman_path)
subprocess.check_call(
(
"datman",
"extract",
"--skip-metadata",
"--accept-partial",
"main",
"../desta",
),
cwd=datman_path,
)
time.sleep(300)
time.sleep(300)

View File

@ -2,7 +2,7 @@ import os.path
from hashlib import sha256
from pathlib import Path
from random import Random
from typing import Union, Tuple
from typing import Tuple, Union
import attr
from immutabledict import immutabledict
@ -46,7 +46,7 @@ def generate_random_file(rng: Random, path: Path) -> FileDescriptor:
sha256_hasher = sha256()
with path.open('wb') as file:
with path.open("wb") as file:
while bytes_to_gen > CHUNK_SIZE:
next_bytes = rng.randbytes(CHUNK_SIZE)
file.write(next_bytes)
@ -64,13 +64,16 @@ def generate_random_file(rng: Random, path: Path) -> FileDescriptor:
file_stat.st_mtime_ns // 1000000,
file_stat.st_mode,
file_stat.st_uid,
file_stat.st_gid
file_stat.st_gid,
)
def generate_random_dir(rng: Random, path: Path, max_remaining_files: int) -> Tuple[DirectoryDescriptor, int]:
def generate_random_dir(
rng: Random, path: Path, max_remaining_files: int
) -> Tuple[DirectoryDescriptor, int]:
"""
Generates a random directory at the given path, and returns its descriptor (and the remaining number of files allowed).
Generates a random directory at the given path, and returns its descriptor
(and the remaining number of files allowed).
:param rng: PRNG to use
:param path: path to use
:param max_remaining_files: The maximum number of files allowed.
@ -92,17 +95,22 @@ def generate_random_dir(rng: Random, path: Path, max_remaining_files: int) -> Tu
if is_file:
contents[filename] = generate_random_file(rng, filepath)
else:
contents[filename], max_remaining_files = generate_random_dir(rng, filepath, max_remaining_files)
contents[filename], max_remaining_files = generate_random_dir(
rng, filepath, max_remaining_files
)
file_stat = os.stat(path)
return DirectoryDescriptor(
immutabledict(contents),
file_stat.st_mtime_ns // 1000000,
file_stat.st_mode,
file_stat.st_uid,
file_stat.st_gid
), max_remaining_files
return (
DirectoryDescriptor(
immutabledict(contents),
file_stat.st_mtime_ns // 1000000,
file_stat.st_mode,
file_stat.st_uid,
file_stat.st_gid,
),
max_remaining_files,
)
def scan_file(path: Path) -> FileDescriptor:
@ -121,7 +129,7 @@ def scan_file(path: Path) -> FileDescriptor:
file_stat.st_mtime_ns // 1000000,
file_stat.st_mode,
file_stat.st_uid,
file_stat.st_gid
file_stat.st_gid,
)
@ -129,7 +137,7 @@ def scan_dir(path: Path) -> DirectoryDescriptor:
contents = dict()
for entry in os.scandir(path):
name = entry.name
if name in ('.', '..'):
if name in (".", ".."):
continue
filepath = path.joinpath(name)
if filepath.is_dir():
@ -145,5 +153,5 @@ def scan_dir(path: Path) -> DirectoryDescriptor:
file_stat.st_mtime_ns // 1000000,
file_stat.st_mode,
file_stat.st_uid,
file_stat.st_gid
file_stat.st_gid,
)

View File

@ -11,7 +11,8 @@ def set_up_simple_datman(path: Path):
subprocess.check_call(("datman", "init"), cwd=path)
with path.joinpath("datman.toml").open("a") as file:
file.write(f"""
file.write(
f"""
[source.srca]
directory = "{path.joinpath("srca")}"
hostname = "{get_hostname()}"
@ -19,4 +20,5 @@ hostname = "{get_hostname()}"
[piles.main]
path = "main"
included_labels = ["precious"]
""")
"""
)

View File

@ -6,4 +6,4 @@ from pathlib import Path
def set_up_simple_yama(path: Path):
path.mkdir(exist_ok=True)
subprocess.check_call(("yama", "init"), cwd=path)
shutil.copyfile("../example_zstd.dict", path.joinpath("important_zstd.dict"))
shutil.copyfile("../example_zstd.dict", path.joinpath("important_zstd.dict"))

18
testsuite/scripts-dev/lint.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/sh -eu
if [ $# -ge 1 ]
then
files=$*
else
files="setup.py datmantests helpers yamatests"
fi
echo "Linting these locations: $files"
echo " ===== Running isort ===== "
isort $files
echo " ===== Running black ===== "
black $files
echo " ===== Running flake8 ===== "
flake8 $files
#echo " ===== Running mypy ===== "
#mypy $files

21
testsuite/setup.cfg Normal file
View File

@ -0,0 +1,21 @@
[flake8]
# line length defaulted to by black
max-line-length = 88
# see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
# for error codes. The ones we ignore are:
# W503: line break before binary operator
# W504: line break after binary operator
# E203: whitespace before ':' (which is contrary to pep8?)
# (this is a subset of those ignored in Synapse)
ignore=W503,W504,E203
[isort]
line_length = 88
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,TESTS,LOCALFOLDER
default_section=THIRDPARTY
known_first_party=scone
known_tests=tests
multi_line_output=3
include_trailing_comma=true
combine_as_imports=true

View File

@ -6,7 +6,7 @@ import os
import sys
from shutil import rmtree
from setuptools import find_packages, setup, Command
from setuptools import Command, find_packages, setup
# Package meta-data.
NAME = "yamadatmantestsuite"
@ -18,21 +18,11 @@ REQUIRES_PYTHON = ">=3.9.0"
VERSION = "0.0.0"
# What packages are required for this module to be executed?
REQUIRED = [
"green",
"attrs",
"immutabledict"
]
REQUIRED = ["green", "attrs", "immutabledict"]
# What packages are optional?
EXTRAS = {
"dev": [
"black==21.7b0",
"flake8==3.9.2",
"isort==5.9.2"
]
}
EXTRAS = {"dev": ["black==21.7b0", "flake8==3.9.2", "isort==5.9.2"]}
# The rest you shouldn't have to touch too much :)
# ------------------------------------------------

View File

@ -1,6 +1,3 @@
from unittest import TestCase
# class TestStoreAndRetrieve(TestCase):
# def test_store_and_retrieve(self):
#
#