summaryrefslogtreecommitdiff
path: root/tests/testutils
diff options
context:
space:
mode:
authorChandan Singh <csingh43@bloomberg.net>2019-11-11 17:07:09 +0000
committerChandan Singh <chandan@chandansingh.net>2019-11-14 21:21:06 +0000
commit122177153b14664a0e4fed85aa4f22b87cfabf56 (patch)
tree032c2e46825af91f6fe27f22b5b567eea2b7935d /tests/testutils
parenta3ee349558f36a220f79665873b36c1b0f990c8e (diff)
downloadbuildstream-122177153b14664a0e4fed85aa4f22b87cfabf56.tar.gz
Reformat code using Black
As discussed over the mailing list, reformat code using Black. This is a one-off change to reformat all our codebase. Moving forward, we shouldn't expect such blanket reformats. Rather, we expect each change to already comply with the Black formatting style.
Diffstat (limited to 'tests/testutils')
-rw-r--r--tests/testutils/artifactshare.py37
-rw-r--r--tests/testutils/element_generators.py24
-rw-r--r--tests/testutils/file_server.py4
-rw-r--r--tests/testutils/filetypegenerator.py2
-rw-r--r--tests/testutils/ftp_server.py6
-rw-r--r--tests/testutils/http_server.py53
-rw-r--r--tests/testutils/junction.py9
-rw-r--r--tests/testutils/patch.py10
-rw-r--r--tests/testutils/python_repo.py45
-rw-r--r--tests/testutils/repo/bzr.py32
-rw-r--r--tests/testutils/repo/git.py71
-rw-r--r--tests/testutils/repo/tar.py14
-rw-r--r--tests/testutils/repo/zip.py16
-rw-r--r--tests/testutils/setuptools.py13
14 files changed, 141 insertions, 195 deletions
diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py
index d96612686..8d0448f8a 100644
--- a/tests/testutils/artifactshare.py
+++ b/tests/testutils/artifactshare.py
@@ -29,7 +29,7 @@ class BaseArtifactShare:
if port is None:
raise Exception("Error occurred when starting artifact server.")
- self.repo = 'http://localhost:{}'.format(port)
+ self.repo = "http://localhost:{}".format(port)
# run():
#
@@ -51,7 +51,7 @@ class BaseArtifactShare:
cleanup_on_sigterm()
server = stack.enter_context(self._create_server())
- port = server.add_insecure_port('localhost:0')
+ port = server.add_insecure_port("localhost:0")
server.start()
except Exception:
q.put(None)
@@ -104,7 +104,6 @@ class DummyArtifactShare(BaseArtifactShare):
# enable_push (bool): Whether the share should allow pushes
#
class ArtifactShare(BaseArtifactShare):
-
def __init__(self, directory, *, quota=None, casd=False, index_only=False):
# The working directory for the artifact share (in case it
@@ -117,9 +116,9 @@ class ArtifactShare(BaseArtifactShare):
# Unless this gets more complicated, just use this directly
# in tests as a remote artifact push/pull configuration
#
- self.repodir = os.path.join(self.directory, 'repo')
+ self.repodir = os.path.join(self.directory, "repo")
os.makedirs(self.repodir)
- self.artifactdir = os.path.join(self.repodir, 'artifacts', 'refs')
+ self.artifactdir = os.path.join(self.repodir, "artifacts", "refs")
os.makedirs(self.artifactdir)
self.cas = CASCache(self.repodir, casd=casd)
@@ -130,12 +129,7 @@ class ArtifactShare(BaseArtifactShare):
super().__init__()
def _create_server(self):
- return create_server(
- self.repodir,
- quota=self.quota,
- enable_push=True,
- index_only=self.index_only,
- )
+ return create_server(self.repodir, quota=self.quota, enable_push=True, index_only=self.index_only,)
# has_object():
#
@@ -159,7 +153,7 @@ class ArtifactShare(BaseArtifactShare):
artifact_path = os.path.join(self.artifactdir, artifact_name)
try:
- with open(artifact_path, 'rb') as f:
+ with open(artifact_path, "rb") as f:
artifact_proto.ParseFromString(f.read())
except FileNotFoundError:
return None
@@ -171,8 +165,7 @@ class ArtifactShare(BaseArtifactShare):
reachable = set()
def reachable_dir(digest):
- self.cas._reachable_refs_dir(
- reachable, digest, update_mtime=False, check_exists=True)
+ self.cas._reachable_refs_dir(reachable, digest, update_mtime=False, check_exists=True)
try:
if str(artifact_proto.files):
@@ -262,20 +255,22 @@ def create_dummy_artifact_share():
share.close()
-statvfs_result = namedtuple('statvfs_result', 'f_blocks f_bfree f_bsize f_bavail')
+statvfs_result = namedtuple("statvfs_result", "f_blocks f_bfree f_bsize f_bavail")
# Assert that a given artifact is in the share
#
-def assert_shared(cli, share, project, element_name, *, project_name='test'):
+def assert_shared(cli, share, project, element_name, *, project_name="test"):
if not share.get_artifact(cli.get_artifact_name(project, project_name, element_name)):
- raise AssertionError("Artifact share at {} does not contain the expected element {}"
- .format(share.repo, element_name))
+ raise AssertionError(
+ "Artifact share at {} does not contain the expected element {}".format(share.repo, element_name)
+ )
# Assert that a given artifact is not in the share
#
-def assert_not_shared(cli, share, project, element_name, *, project_name='test'):
+def assert_not_shared(cli, share, project, element_name, *, project_name="test"):
if share.get_artifact(cli.get_artifact_name(project, project_name, element_name)):
- raise AssertionError("Artifact share at {} unexpectedly contains the element {}"
- .format(share.repo, element_name))
+ raise AssertionError(
+ "Artifact share at {} unexpectedly contains the element {}".format(share.repo, element_name)
+ )
diff --git a/tests/testutils/element_generators.py b/tests/testutils/element_generators.py
index 0fbca7f3e..6da465ab7 100644
--- a/tests/testutils/element_generators.py
+++ b/tests/testutils/element_generators.py
@@ -28,8 +28,8 @@ def create_element_size(name, project_dir, elements_path, dependencies, size):
os.makedirs(full_elements_path, exist_ok=True)
# Create a git repo
- repodir = os.path.join(project_dir, 'repos')
- repo = create_repo('git', repodir, subdir=name)
+ repodir = os.path.join(project_dir, "repos")
+ repo = create_repo("git", repodir, subdir=name)
with utils._tempdir(dir=project_dir) as tmp:
@@ -38,26 +38,24 @@ def create_element_size(name, project_dir, elements_path, dependencies, size):
# part; this ensures we never include a .git/ directory
# in the cached artifacts for these sized elements.
#
- datadir = os.path.join(tmp, 'data')
+ datadir = os.path.join(tmp, "data")
os.makedirs(datadir)
# Use /dev/urandom to create the sized file in the datadir
- with open(os.path.join(datadir, name), 'wb+') as f:
+ with open(os.path.join(datadir, name), "wb+") as f:
f.write(os.urandom(size))
# Create the git repo from the temp directory
ref = repo.create(tmp)
element = {
- 'kind': 'import',
- 'sources': [
- repo.source_config(ref=ref)
- ],
- 'config': {
+ "kind": "import",
+ "sources": [repo.source_config(ref=ref)],
+ "config": {
# Extract only the data directory
- 'source': 'data'
+ "source": "data"
},
- 'depends': dependencies
+ "depends": dependencies,
}
_yaml.roundtrip_dump(element, os.path.join(project_dir, elements_path, name))
@@ -91,9 +89,9 @@ def update_element_size(name, project_dir, repo, size):
new_file = os.path.join(tmp, name)
# Use /dev/urandom to create the sized file in the datadir
- with open(new_file, 'wb+') as f:
+ with open(new_file, "wb+") as f:
f.write(os.urandom(size))
# Modify the git repo with a new commit to the same path,
# replacing the original file with a new one.
- repo.modify_file(new_file, os.path.join('data', name))
+ repo.modify_file(new_file, os.path.join("data", name))
diff --git a/tests/testutils/file_server.py b/tests/testutils/file_server.py
index 05f896013..3e6e41954 100644
--- a/tests/testutils/file_server.py
+++ b/tests/testutils/file_server.py
@@ -6,9 +6,9 @@ from .http_server import SimpleHttpServer
@contextmanager
def create_file_server(file_server_type):
- if file_server_type == 'FTP':
+ if file_server_type == "FTP":
server = SimpleFtpServer()
- elif file_server_type == 'HTTP':
+ elif file_server_type == "HTTP":
server = SimpleHttpServer()
else:
assert False
diff --git a/tests/testutils/filetypegenerator.py b/tests/testutils/filetypegenerator.py
index 8b7d818d8..41c502be2 100644
--- a/tests/testutils/filetypegenerator.py
+++ b/tests/testutils/filetypegenerator.py
@@ -39,7 +39,7 @@ def generate_file_types(path):
clean()
- with open(path, 'w'):
+ with open(path, "w"):
pass
yield
clean()
diff --git a/tests/testutils/ftp_server.py b/tests/testutils/ftp_server.py
index 52c05f8ba..7eda90b70 100644
--- a/tests/testutils/ftp_server.py
+++ b/tests/testutils/ftp_server.py
@@ -11,7 +11,7 @@ class SimpleFtpServer(multiprocessing.Process):
self.authorizer = DummyAuthorizer()
handler = FTPHandler
handler.authorizer = self.authorizer
- self.server = FTPServer(('127.0.0.1', 0), handler)
+ self.server = FTPServer(("127.0.0.1", 0), handler)
def run(self):
self.server.serve_forever()
@@ -26,7 +26,7 @@ class SimpleFtpServer(multiprocessing.Process):
self.authorizer.add_anonymous(cwd)
def add_user(self, user, password, cwd):
- self.authorizer.add_user(user, password, cwd, perm='elradfmwMT')
+ self.authorizer.add_user(user, password, cwd, perm="elradfmwMT")
def base_url(self):
- return 'ftp://127.0.0.1:{}'.format(self.server.address[1])
+ return "ftp://127.0.0.1:{}".format(self.server.address[1])
diff --git a/tests/testutils/http_server.py b/tests/testutils/http_server.py
index b72e745c5..8591159f8 100644
--- a/tests/testutils/http_server.py
+++ b/tests/testutils/http_server.py
@@ -11,45 +11,44 @@ class Unauthorized(Exception):
class RequestHandler(SimpleHTTPRequestHandler):
-
def get_root_dir(self):
- authorization = self.headers.get('authorization')
+ authorization = self.headers.get("authorization")
if not authorization:
if not self.server.anonymous_dir:
- raise Unauthorized('unauthorized')
+ raise Unauthorized("unauthorized")
return self.server.anonymous_dir
else:
authorization = authorization.split()
- if len(authorization) != 2 or authorization[0].lower() != 'basic':
- raise Unauthorized('unauthorized')
+ if len(authorization) != 2 or authorization[0].lower() != "basic":
+ raise Unauthorized("unauthorized")
try:
- decoded = base64.decodebytes(authorization[1].encode('ascii'))
- user, password = decoded.decode('ascii').split(':')
+ decoded = base64.decodebytes(authorization[1].encode("ascii"))
+ user, password = decoded.decode("ascii").split(":")
expected_password, directory = self.server.users[user]
if password == expected_password:
return directory
- except: # noqa
- raise Unauthorized('unauthorized')
+ except: # noqa
+ raise Unauthorized("unauthorized")
return None
def unauthorized(self):
shortmsg, longmsg = self.responses[HTTPStatus.UNAUTHORIZED]
self.send_response(HTTPStatus.UNAUTHORIZED, shortmsg)
- self.send_header('Connection', 'close')
-
- content = (self.error_message_format % {
- 'code': HTTPStatus.UNAUTHORIZED,
- 'message': html.escape(longmsg, quote=False),
- 'explain': html.escape(longmsg, quote=False)
- })
- body = content.encode('UTF-8', 'replace')
- self.send_header('Content-Type', self.error_content_type)
- self.send_header('Content-Length', str(len(body)))
- self.send_header('WWW-Authenticate', 'Basic realm="{}"'.format(self.server.realm))
+ self.send_header("Connection", "close")
+
+ content = self.error_message_format % {
+ "code": HTTPStatus.UNAUTHORIZED,
+ "message": html.escape(longmsg, quote=False),
+ "explain": html.escape(longmsg, quote=False),
+ }
+ body = content.encode("UTF-8", "replace")
+ self.send_header("Content-Type", self.error_content_type)
+ self.send_header("Content-Length", str(len(body)))
+ self.send_header("WWW-Authenticate", 'Basic realm="{}"'.format(self.server.realm))
self.end_headers()
self.end_headers()
- if self.command != 'HEAD' and body:
+ if self.command != "HEAD" and body:
self.wfile.write(body)
def do_GET(self):
@@ -65,11 +64,11 @@ class RequestHandler(SimpleHTTPRequestHandler):
self.unauthorized()
def translate_path(self, path):
- path = path.split('?', 1)[0]
- path = path.split('#', 1)[0]
+ path = path.split("?", 1)[0]
+ path = path.split("#", 1)[0]
path = posixpath.normpath(path)
assert posixpath.isabs(path)
- path = posixpath.relpath(path, '/')
+ path = posixpath.relpath(path, "/")
return os.path.join(self.get_root_dir(), path)
@@ -77,14 +76,14 @@ class AuthHTTPServer(HTTPServer):
def __init__(self, *args, **kwargs):
self.users = {}
self.anonymous_dir = None
- self.realm = 'Realm'
+ self.realm = "Realm"
super().__init__(*args, **kwargs)
class SimpleHttpServer(multiprocessing.Process):
def __init__(self):
super().__init__()
- self.server = AuthHTTPServer(('127.0.0.1', 0), RequestHandler)
+ self.server = AuthHTTPServer(("127.0.0.1", 0), RequestHandler)
self.started = False
def start(self):
@@ -107,4 +106,4 @@ class SimpleHttpServer(multiprocessing.Process):
self.server.users[user] = (password, cwd)
def base_url(self):
- return 'http://127.0.0.1:{}'.format(self.server.server_port)
+ return "http://127.0.0.1:{}".format(self.server.server_port)
diff --git a/tests/testutils/junction.py b/tests/testutils/junction.py
index e867695c4..c086f6f17 100644
--- a/tests/testutils/junction.py
+++ b/tests/testutils/junction.py
@@ -19,17 +19,12 @@ def generate_junction(tmpdir, subproject_path, junction_path, *, store_ref=True)
# Create a repo to hold the subproject and generate
# a junction element for it
#
- repo = create_repo('git', str(tmpdir))
+ repo = create_repo("git", str(tmpdir))
source_ref = ref = repo.create(subproject_path)
if not store_ref:
source_ref = None
- element = {
- 'kind': 'junction',
- 'sources': [
- repo.source_config(ref=source_ref)
- ]
- }
+ element = {"kind": "junction", "sources": [repo.source_config(ref=source_ref)]}
_yaml.roundtrip_dump(element, junction_path)
return ref
diff --git a/tests/testutils/patch.py b/tests/testutils/patch.py
index df287f374..85b38def8 100644
--- a/tests/testutils/patch.py
+++ b/tests/testutils/patch.py
@@ -3,19 +3,17 @@ import subprocess
def apply(file, patch):
try:
- subprocess.check_output(['patch', file, patch])
+ subprocess.check_output(["patch", file, patch])
except subprocess.CalledProcessError as e:
- message = "Patch failed with exit code {}\n Output:\n {}".format(
- e.returncode, e.output)
+ message = "Patch failed with exit code {}\n Output:\n {}".format(e.returncode, e.output)
print(message)
raise
def remove(file, patch):
try:
- subprocess.check_output(['patch', '--reverse', file, patch])
+ subprocess.check_output(["patch", "--reverse", file, patch])
except subprocess.CalledProcessError as e:
- message = "patch --reverse failed with exit code {}\n Output:\n {}".format(
- e.returncode, e.output)
+ message = "patch --reverse failed with exit code {}\n Output:\n {}".format(e.returncode, e.output)
print(message)
raise
diff --git a/tests/testutils/python_repo.py b/tests/testutils/python_repo.py
index c8e5bf343..7d9ae4e47 100644
--- a/tests/testutils/python_repo.py
+++ b/tests/testutils/python_repo.py
@@ -7,7 +7,7 @@ import sys
import pytest
-SETUP_TEMPLATE = '''\
+SETUP_TEMPLATE = """\
from setuptools import setup
setup(
@@ -22,18 +22,18 @@ setup(
]
}}
)
-'''
+"""
# All packages generated via generate_pip_package will have the functions below
-INIT_TEMPLATE = '''\
+INIT_TEMPLATE = """\
def main():
print('This is {name}')
def hello(actor='world'):
print('Hello {{}}! This is {name}'.format(actor))
-'''
+"""
-HTML_TEMPLATE = '''\
+HTML_TEMPLATE = """\
<html>
<head>
<title>Links for {name}</title>
@@ -42,7 +42,7 @@ HTML_TEMPLATE = '''\
<a href='{name}-{version}.tar.gz'>{name}-{version}.tar.gz</a><br />
</body>
</html>
-'''
+"""
# Creates a simple python source distribution and copies this into a specified
@@ -57,11 +57,11 @@ HTML_TEMPLATE = '''\
# Returns:
# None
#
-def generate_pip_package(tmpdir, pypi, name, version='0.1', dependencies=None):
+def generate_pip_package(tmpdir, pypi, name, version="0.1", dependencies=None):
if dependencies is None:
dependencies = []
# check if package already exists in pypi
- pypi_package = os.path.join(pypi, re.sub('[^0-9a-zA-Z]+', '-', name))
+ pypi_package = os.path.join(pypi, re.sub("[^0-9a-zA-Z]+", "-", name))
if os.path.exists(pypi_package):
return
@@ -73,29 +73,22 @@ def generate_pip_package(tmpdir, pypi, name, version='0.1', dependencies=None):
# `-- package
# `-- __init__.py
#
- setup_file = os.path.join(tmpdir, 'setup.py')
- pkgdirname = re.sub('[^0-9a-zA-Z]+', '', name)
- with open(setup_file, 'w') as f:
- f.write(
- SETUP_TEMPLATE.format(
- name=name,
- version=version,
- pkgdirname=pkgdirname,
- pkgdeps=dependencies
- )
- )
+ setup_file = os.path.join(tmpdir, "setup.py")
+ pkgdirname = re.sub("[^0-9a-zA-Z]+", "", name)
+ with open(setup_file, "w") as f:
+ f.write(SETUP_TEMPLATE.format(name=name, version=version, pkgdirname=pkgdirname, pkgdeps=dependencies))
os.chmod(setup_file, 0o755)
package = os.path.join(tmpdir, pkgdirname)
os.makedirs(package)
- main_file = os.path.join(package, '__init__.py')
- with open(main_file, 'w') as f:
+ main_file = os.path.join(package, "__init__.py")
+ with open(main_file, "w") as f:
f.write(INIT_TEMPLATE.format(name=name))
os.chmod(main_file, 0o644)
# Run sdist with a fresh process
- p = subprocess.run([sys.executable, 'setup.py', 'sdist'], cwd=tmpdir)
+ p = subprocess.run([sys.executable, "setup.py", "sdist"], cwd=tmpdir)
assert p.returncode == 0
# create directory for this package in pypi resulting in a directory
@@ -109,12 +102,12 @@ def generate_pip_package(tmpdir, pypi, name, version='0.1', dependencies=None):
os.makedirs(pypi_package)
# add an index html page
- index_html = os.path.join(pypi_package, 'index.html')
- with open(index_html, 'w') as f:
+ index_html = os.path.join(pypi_package, "index.html")
+ with open(index_html, "w") as f:
f.write(HTML_TEMPLATE.format(name=name, version=version))
# copy generated tarfile to pypi package
- dist_dir = os.path.join(tmpdir, 'dist')
+ dist_dir = os.path.join(tmpdir, "dist")
for tar in os.listdir(dist_dir):
tarpath = os.path.join(dist_dir, tar)
shutil.copy(tarpath, pypi_package)
@@ -123,7 +116,7 @@ def generate_pip_package(tmpdir, pypi, name, version='0.1', dependencies=None):
@pytest.fixture
def setup_pypi_repo(tmpdir):
def create_pkgdir(package):
- pkgdirname = re.sub('[^0-9a-zA-Z]+', '', package)
+ pkgdirname = re.sub("[^0-9a-zA-Z]+", "", package)
pkgdir = os.path.join(str(tmpdir), pkgdirname)
os.makedirs(pkgdir)
return pkgdir
diff --git a/tests/testutils/repo/bzr.py b/tests/testutils/repo/bzr.py
index 074712af1..b6983416e 100644
--- a/tests/testutils/repo/bzr.py
+++ b/tests/testutils/repo/bzr.py
@@ -7,7 +7,6 @@ from buildstream.testing._utils.site import BZR, BZR_ENV, HAVE_BZR
class Bzr(Repo):
-
def __init__(self, directory, subdir):
if not HAVE_BZR:
pytest.skip("bzr is not available")
@@ -20,34 +19,29 @@ class Bzr(Repo):
def create(self, directory):
# Work around race condition in bzr's creation of ~/.bazaar in
# ensure_config_dir_exists() when running tests in parallel.
- bazaar_config_dir = os.path.expanduser('~/.bazaar')
+ bazaar_config_dir = os.path.expanduser("~/.bazaar")
os.makedirs(bazaar_config_dir, exist_ok=True)
- branch_dir = os.path.join(self.repo, 'trunk')
+ branch_dir = os.path.join(self.repo, "trunk")
- subprocess.call([self.bzr, 'init-repo', self.repo], env=self.env)
- subprocess.call([self.bzr, 'init', branch_dir], env=self.env)
+ subprocess.call([self.bzr, "init-repo", self.repo], env=self.env)
+ subprocess.call([self.bzr, "init", branch_dir], env=self.env)
self.copy_directory(directory, branch_dir)
- subprocess.call([self.bzr, 'add', '.'], env=self.env, cwd=branch_dir)
- subprocess.call([self.bzr, 'commit', '--message="Initial commit"'],
- env=self.env, cwd=branch_dir)
+ subprocess.call([self.bzr, "add", "."], env=self.env, cwd=branch_dir)
+ subprocess.call([self.bzr, "commit", '--message="Initial commit"'], env=self.env, cwd=branch_dir)
return self.latest_commit()
def source_config(self, ref=None):
- config = {
- 'kind': 'bzr',
- 'url': 'file://' + self.repo,
- 'track': 'trunk'
- }
+ config = {"kind": "bzr", "url": "file://" + self.repo, "track": "trunk"}
if ref is not None:
- config['ref'] = ref
+ config["ref"] = ref
return config
def latest_commit(self):
- return subprocess.check_output([
- self.bzr, 'version-info',
- '--custom', '--template={revno}',
- os.path.join(self.repo, 'trunk')
- ], env=self.env, universal_newlines=True).strip()
+ return subprocess.check_output(
+ [self.bzr, "version-info", "--custom", "--template={revno}", os.path.join(self.repo, "trunk")],
+ env=self.env,
+ universal_newlines=True,
+ ).strip()
diff --git a/tests/testutils/repo/git.py b/tests/testutils/repo/git.py
index 46694fcf2..b9360e9cd 100644
--- a/tests/testutils/repo/git.py
+++ b/tests/testutils/repo/git.py
@@ -9,7 +9,6 @@ from buildstream.testing._utils.site import GIT, GIT_ENV, HAVE_GIT
class Git(Repo):
-
def __init__(self, directory, subdir):
if not HAVE_GIT:
pytest.skip("git is not available")
@@ -24,99 +23,87 @@ class Git(Repo):
def _run_git(self, *args, **kwargs):
argv = [GIT]
argv.extend(args)
- if 'env' not in kwargs:
- kwargs['env'] = dict(self.env, PWD=self.repo)
- kwargs.setdefault('cwd', self.repo)
- kwargs.setdefault('check', True)
+ if "env" not in kwargs:
+ kwargs["env"] = dict(self.env, PWD=self.repo)
+ kwargs.setdefault("cwd", self.repo)
+ kwargs.setdefault("check", True)
return subprocess.run(argv, **kwargs)
def create(self, directory):
self.copy_directory(directory, self.repo)
- self._run_git('init', '.')
- self._run_git('add', '.')
- self._run_git('commit', '-m', 'Initial commit')
+ self._run_git("init", ".")
+ self._run_git("add", ".")
+ self._run_git("commit", "-m", "Initial commit")
return self.latest_commit()
def add_tag(self, tag):
- self._run_git('tag', tag)
+ self._run_git("tag", tag)
def add_annotated_tag(self, tag, message):
- self._run_git('tag', '-a', tag, '-m', message)
+ self._run_git("tag", "-a", tag, "-m", message)
def add_commit(self):
- self._run_git('commit', '--allow-empty', '-m', 'Additional commit')
+ self._run_git("commit", "--allow-empty", "-m", "Additional commit")
return self.latest_commit()
def add_file(self, filename):
shutil.copy(filename, self.repo)
- self._run_git('add', os.path.basename(filename))
- self._run_git('commit', '-m', 'Added {}'.format(os.path.basename(filename)))
+ self._run_git("add", os.path.basename(filename))
+ self._run_git("commit", "-m", "Added {}".format(os.path.basename(filename)))
return self.latest_commit()
def modify_file(self, new_file, path):
shutil.copy(new_file, os.path.join(self.repo, path))
- self._run_git('commit', path, '-m', 'Modified {}'.format(os.path.basename(path)))
+ self._run_git("commit", path, "-m", "Modified {}".format(os.path.basename(path)))
return self.latest_commit()
def add_submodule(self, subdir, url=None, checkout=None):
submodule = {}
if checkout is not None:
- submodule['checkout'] = checkout
+ submodule["checkout"] = checkout
if url is not None:
- submodule['url'] = url
+ submodule["url"] = url
self.submodules[subdir] = submodule
- self._run_git('submodule', 'add', url, subdir)
- self._run_git('commit', '-m', 'Added the submodule')
+ self._run_git("submodule", "add", url, subdir)
+ self._run_git("commit", "-m", "Added the submodule")
return self.latest_commit()
# This can also be used to a file or a submodule
def remove_path(self, path):
- self._run_git('rm', path)
- self._run_git('commit', '-m', 'Removing {}'.format(path))
+ self._run_git("rm", path)
+ self._run_git("commit", "-m", "Removing {}".format(path))
return self.latest_commit()
def source_config(self, ref=None):
return self.source_config_extra(ref)
def source_config_extra(self, ref=None, checkout_submodules=None):
- config = {
- 'kind': 'git',
- 'url': 'file://' + self.repo,
- 'track': 'master'
- }
+ config = {"kind": "git", "url": "file://" + self.repo, "track": "master"}
if ref is not None:
- config['ref'] = ref
+ config["ref"] = ref
if checkout_submodules is not None:
- config['checkout-submodules'] = checkout_submodules
+ config["checkout-submodules"] = checkout_submodules
if self.submodules:
- config['submodules'] = dict(self.submodules)
+ config["submodules"] = dict(self.submodules)
return config
def latest_commit(self):
- return self._run_git(
- 'rev-parse', 'HEAD',
- stdout=subprocess.PIPE,
- universal_newlines=True,
- ).stdout.strip()
+ return self._run_git("rev-parse", "HEAD", stdout=subprocess.PIPE, universal_newlines=True,).stdout.strip()
def branch(self, branch_name):
- self._run_git('checkout', '-b', branch_name)
+ self._run_git("checkout", "-b", branch_name)
def delete_tag(self, tag_name):
- self._run_git('tag', '-d', tag_name)
+ self._run_git("tag", "-d", tag_name)
def checkout(self, commit):
- self._run_git('checkout', commit)
+ self._run_git("checkout", commit)
def merge(self, commit):
- self._run_git('merge', '-m', 'Merge', commit)
+ self._run_git("merge", "-m", "Merge", commit)
return self.latest_commit()
def rev_parse(self, rev):
- return self._run_git(
- 'rev-parse', rev,
- stdout=subprocess.PIPE,
- universal_newlines=True,
- ).stdout.strip()
+ return self._run_git("rev-parse", rev, stdout=subprocess.PIPE, universal_newlines=True,).stdout.strip()
diff --git a/tests/testutils/repo/tar.py b/tests/testutils/repo/tar.py
index 63231fa4b..3eb9d896b 100644
--- a/tests/testutils/repo/tar.py
+++ b/tests/testutils/repo/tar.py
@@ -7,9 +7,8 @@ from buildstream.testing import Repo
class Tar(Repo):
-
def create(self, directory):
- tarball = os.path.join(self.repo, 'file.tar.gz')
+ tarball = os.path.join(self.repo, "file.tar.gz")
old_dir = os.getcwd()
os.chdir(directory)
@@ -20,14 +19,9 @@ class Tar(Repo):
return sha256sum(tarball)
def source_config(self, ref=None):
- tarball = os.path.join(self.repo, 'file.tar.gz')
- config = {
- 'kind': 'tar',
- 'url': 'file://' + tarball,
- 'directory': '',
- 'base-dir': ''
- }
+ tarball = os.path.join(self.repo, "file.tar.gz")
+ config = {"kind": "tar", "url": "file://" + tarball, "directory": "", "base-dir": ""}
if ref is not None:
- config['ref'] = ref
+ config["ref"] = ref
return config
diff --git a/tests/testutils/repo/zip.py b/tests/testutils/repo/zip.py
index df3f834a9..38419e642 100644
--- a/tests/testutils/repo/zip.py
+++ b/tests/testutils/repo/zip.py
@@ -7,14 +7,13 @@ from buildstream.testing import Repo
class Zip(Repo):
-
def create(self, directory):
- archive = os.path.join(self.repo, 'file.zip')
+ archive = os.path.join(self.repo, "file.zip")
old_dir = os.getcwd()
os.chdir(directory)
with zipfile.ZipFile(archive, "w") as zipfp:
- for root, dirs, files in os.walk('.'):
+ for root, dirs, files in os.walk("."):
names = dirs + files
names = [os.path.join(root, name) for name in names]
@@ -26,14 +25,9 @@ class Zip(Repo):
return sha256sum(archive)
def source_config(self, ref=None):
- archive = os.path.join(self.repo, 'file.zip')
- config = {
- 'kind': 'zip',
- 'url': 'file://' + archive,
- 'directory': '',
- 'base-dir': ''
- }
+ archive = os.path.join(self.repo, "file.zip")
+ config = {"kind": "zip", "url": "file://" + archive, "directory": "", "base-dir": ""}
if ref is not None:
- config['ref'] = ref
+ config["ref"] = ref
return config
diff --git a/tests/testutils/setuptools.py b/tests/testutils/setuptools.py
index cb61e1976..0f7f30f91 100644
--- a/tests/testutils/setuptools.py
+++ b/tests/testutils/setuptools.py
@@ -4,19 +4,17 @@ import pkg_resources
# A mock setuptools dist object.
-class MockDist():
+class MockDist:
def __init__(self, datafiles, module_name):
self.datafiles = datafiles
self.module_name = module_name
def get_resource_filename(self, *_args, **_kwargs):
- return os.path.join(self.datafiles.dirname,
- self.datafiles.basename,
- self.module_name)
+ return os.path.join(self.datafiles.dirname, self.datafiles.basename, self.module_name)
# A mock setuptools entry object.
-class MockEntry():
+class MockEntry:
def __init__(self, datafiles, module_name):
self.dist = MockDist(datafiles, module_name)
self.module_name = module_name
@@ -30,7 +28,7 @@ class MockEntry():
@pytest.fixture()
def entry_fixture(monkeypatch):
def patch(datafiles, entry_point, lookup_string):
- dist, package = lookup_string.split(':')
+ dist, package = lookup_string.split(":")
def mock_entry(pdist, pentry_point, ppackage):
assert pdist == dist
@@ -38,6 +36,7 @@ def entry_fixture(monkeypatch):
assert ppackage == package
return MockEntry(datafiles, package)
- monkeypatch.setattr(pkg_resources, 'get_entry_info', mock_entry)
+
+ monkeypatch.setattr(pkg_resources, "get_entry_info", mock_entry)
return patch