Tristan Van Berkom pushed to branch master at BuildStream / buildstream
Commits:
-
4ca37dcd
by Tristan Van Berkom at 2019-01-16T15:47:21Z
-
6286d820
by Tristan Van Berkom at 2019-01-16T15:47:21Z
-
471af316
by Tristan Van Berkom at 2019-01-16T16:32:52Z
4 changed files:
- conftest.py
- tests/integration/pullbuildtrees.py
- tests/integration/source-determinism.py
- tests/testutils/runcli.py
Changes:
| ... | ... | @@ -17,15 +17,23 @@ |
| 17 | 17 |
#
|
| 18 | 18 |
# Authors:
|
| 19 | 19 |
# Tristan Maat <tristan maat codethink co uk>
|
| 20 |
- |
|
| 20 |
+#
|
|
| 21 | 21 |
import os
|
| 22 | 22 |
import shutil
|
| 23 |
- |
|
| 23 |
+import tempfile
|
|
| 24 | 24 |
import pytest
|
| 25 |
- |
|
| 26 | 25 |
from buildstream._platform.platform import Platform
|
| 27 | 26 |
|
| 27 |
+#
|
|
| 28 |
+# This file is loaded by pytest, we use it to add a custom
|
|
| 29 |
+# `--integration` option to our test suite, and to install
|
|
| 30 |
+# a session scope fixture.
|
|
| 31 |
+#
|
|
| 32 |
+ |
|
| 28 | 33 |
|
| 34 |
+#################################################
|
|
| 35 |
+# Implement pytest option #
|
|
| 36 |
+#################################################
|
|
| 29 | 37 |
def pytest_addoption(parser):
|
| 30 | 38 |
parser.addoption('--integration', action='store_true', default=False,
|
| 31 | 39 |
help='Run integration tests')
|
| ... | ... | @@ -36,26 +44,57 @@ def pytest_runtest_setup(item): |
| 36 | 44 |
pytest.skip('skipping integration test')
|
| 37 | 45 |
|
| 38 | 46 |
|
| 47 |
+#################################################
|
|
| 48 |
+# integration_cache fixture #
|
|
| 49 |
+#################################################
|
|
| 50 |
+#
|
|
| 51 |
+# This is yielded by the `integration_cache` fixture
|
|
| 52 |
+#
|
|
| 53 |
+class IntegrationCache():
|
|
| 54 |
+ |
|
| 55 |
+ def __init__(self, cache):
|
|
| 56 |
+ cache = os.path.abspath(cache)
|
|
| 57 |
+ |
|
| 58 |
+ # Use the same sources every time
|
|
| 59 |
+ self.sources = os.path.join(cache, 'sources')
|
|
| 60 |
+ |
|
| 61 |
+ # Create a temp directory for the duration of the test for
|
|
| 62 |
+ # the artifacts directory
|
|
| 63 |
+ try:
|
|
| 64 |
+ self.artifacts = tempfile.mkdtemp(dir=cache, prefix='artifacts-')
|
|
| 65 |
+ except OSError as e:
|
|
| 66 |
+ raise AssertionError("Unable to create test directory !") from e
|
|
| 67 |
+ |
|
| 68 |
+ |
|
| 39 | 69 |
@pytest.fixture(scope='session')
|
| 40 | 70 |
def integration_cache(request):
|
| 41 | 71 |
|
| 42 |
- # Set the tempdir to the INTEGRATION_CACHE variable, or the
|
|
| 72 |
+ # Set the cache dir to the INTEGRATION_CACHE variable, or the
|
|
| 43 | 73 |
# default if that is not set.
|
| 44 | 74 |
if 'INTEGRATION_CACHE' in os.environ:
|
| 45 | 75 |
cache_dir = os.environ['INTEGRATION_CACHE']
|
| 46 | 76 |
else:
|
| 47 | 77 |
cache_dir = os.path.abspath('./integration-cache')
|
| 48 | 78 |
|
| 49 |
- yield cache_dir
|
|
| 79 |
+ cache = IntegrationCache(cache_dir)
|
|
| 80 |
+ |
|
| 81 |
+ yield cache
|
|
| 50 | 82 |
|
| 51 | 83 |
# Clean up the artifacts after each test run - we only want to
|
| 52 |
- # cache sources
|
|
| 84 |
+ # cache sources between runs
|
|
| 53 | 85 |
try:
|
| 54 |
- shutil.rmtree(os.path.join(cache_dir, 'artifacts'))
|
|
| 86 |
+ shutil.rmtree(cache.artifacts)
|
|
| 55 | 87 |
except FileNotFoundError:
|
| 56 | 88 |
pass
|
| 57 | 89 |
|
| 58 | 90 |
|
| 91 |
+#################################################
|
|
| 92 |
+# Automatically reset the platform #
|
|
| 93 |
+#################################################
|
|
| 94 |
+#
|
|
| 95 |
+# This might need some refactor, maybe buildstream
|
|
| 96 |
+# needs to cleanup more gracefully and we could remove this.
|
|
| 97 |
+#
|
|
| 59 | 98 |
def clean_platform_cache():
|
| 60 | 99 |
Platform._instance = None
|
| 61 | 100 |
|
| ... | ... | @@ -32,7 +32,7 @@ def default_state(cli, tmpdir, share): |
| 32 | 32 |
@pytest.mark.integration
|
| 33 | 33 |
@pytest.mark.datafiles(DATA_DIR)
|
| 34 | 34 |
@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
|
| 35 |
-def test_pullbuildtrees(cli, tmpdir, datafiles, integration_cache):
|
|
| 35 |
+def test_pullbuildtrees(cli, tmpdir, datafiles):
|
|
| 36 | 36 |
project = os.path.join(datafiles.dirname, datafiles.basename)
|
| 37 | 37 |
element_name = 'autotools/amhello.bst'
|
| 38 | 38 |
|
| ... | ... | @@ -94,7 +94,7 @@ def test_deterministic_source_umask(cli, tmpdir, datafiles, kind, integration_ca |
| 94 | 94 |
return f.read()
|
| 95 | 95 |
finally:
|
| 96 | 96 |
os.umask(old_umask)
|
| 97 |
- cache_dir = os.path.join(integration_cache, 'artifacts')
|
|
| 97 |
+ cache_dir = integration_cache.artifacts
|
|
| 98 | 98 |
cli.remove_artifact_from_cache(project, element_name,
|
| 99 | 99 |
cache_dir=cache_dir)
|
| 100 | 100 |
|
| ... | ... | @@ -156,7 +156,7 @@ def test_deterministic_source_local(cli, tmpdir, datafiles, integration_cache): |
| 156 | 156 |
with open(os.path.join(checkoutdir, 'ls-l'), 'r') as f:
|
| 157 | 157 |
return f.read()
|
| 158 | 158 |
finally:
|
| 159 |
- cache_dir = os.path.join(integration_cache, 'artifacts')
|
|
| 159 |
+ cache_dir = integration_cache.artifacts
|
|
| 160 | 160 |
cli.remove_artifact_from_cache(project, element_name,
|
| 161 | 161 |
cache_dir=cache_dir)
|
| 162 | 162 |
|
| ... | ... | @@ -525,8 +525,8 @@ def cli_integration(tmpdir, integration_cache): |
| 525 | 525 |
# We want to cache sources for integration tests more permanently,
|
| 526 | 526 |
# to avoid downloading the huge base-sdk repeatedly
|
| 527 | 527 |
fixture.configure({
|
| 528 |
- 'sourcedir': os.path.join(integration_cache, 'sources'),
|
|
| 529 |
- 'artifactdir': os.path.join(integration_cache, 'artifacts')
|
|
| 528 |
+ 'sourcedir': integration_cache.sources,
|
|
| 529 |
+ 'artifactdir': integration_cache.artifacts
|
|
| 530 | 530 |
})
|
| 531 | 531 |
|
| 532 | 532 |
return fixture
|
