diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-04 17:33:40 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-04 17:33:40 +0900 |
commit | e19e7a6e41770806db066152d9e4ca6694a98b68 (patch) | |
tree | e4cc3dfd04207c4bed49eccd05cd474c2fc32152 | |
parent | 5192c83a9ed6b42e17f199bdfcefb6b7b96e5244 (diff) | |
download | buildstream-e19e7a6e41770806db066152d9e4ca6694a98b68.tar.gz |
tests/sources/local.py: Migrated test to use frontend fixtures
-rw-r--r-- | tests/sources/local.py | 81 | ||||
-rw-r--r-- | tests/sources/local/basic/target.bst | 2 | ||||
-rw-r--r-- | tests/sources/local/directory/target.bst | 2 |
3 files changed, 45 insertions, 40 deletions
diff --git a/tests/sources/local.py b/tests/sources/local.py index 50cec0821..c01f270d3 100644 --- a/tests/sources/local.py +++ b/tests/sources/local.py @@ -1,11 +1,9 @@ import os import pytest -import tempfile +from buildstream._pipeline import PipelineError from buildstream import SourceError - -# import our common fixture -from .fixture import Setup +from tests.testutils import cli DATA_DIR = os.path.join( os.path.dirname(os.path.realpath(__file__)), @@ -14,48 +12,55 @@ DATA_DIR = os.path.join( @pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) -def test_create_source(tmpdir, datafiles): - setup = Setup(datafiles, 'target.bst', tmpdir) - assert(setup.source.get_kind() == 'local') - - -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) -def test_preflight(tmpdir, datafiles): - setup = Setup(datafiles, 'target.bst', tmpdir) - assert(setup.source.get_kind() == 'local') - - # Just expect that this passes without throwing any exception - setup.source.preflight() - - -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) -def test_preflight_fail(tmpdir, datafiles): - setup = Setup(datafiles, 'target.bst', tmpdir) - assert(setup.source.get_kind() == 'local') +def test_missing_file(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) - # Delete the file which the local source wants + # Removing the local file causes preflight to fail localfile = os.path.join(datafiles.dirname, datafiles.basename, 'file.txt') os.remove(localfile) - # Expect a preflight error - with pytest.raises(SourceError) as exc: - setup.source.preflight() + result = cli.run(project=project, args=[ + 'show', 'target.bst' + ]) + assert result.exit_code != 0 + assert result.exception + assert isinstance(result.exception, SourceError) @pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) -def test_stage_file(tmpdir, datafiles): - setup = Setup(datafiles, 'target.bst', tmpdir) - assert(setup.source.get_kind() == 'local') +def test_stage_file(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + checkoutdir = os.path.join(str(tmpdir), "checkout") - setup.source.stage(setup.context.builddir) - assert(os.path.exists(os.path.join(setup.context.builddir, 'file.txt'))) + # Track, fetch, build, checkout + result = cli.run(project=project, args=['track', 'target.bst']) + assert result.exit_code == 0 + result = cli.run(project=project, args=['fetch', 'target.bst']) + assert result.exit_code == 0 + result = cli.run(project=project, args=['build', 'target.bst']) + assert result.exit_code == 0 + result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) + assert result.exit_code == 0 + # Check that the checkout contains the expected file + assert(os.path.exists(os.path.join(checkoutdir, 'file.txt'))) -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'directory')) -def test_stage_directory(tmpdir, datafiles): - setup = Setup(datafiles, 'target.bst', tmpdir) - assert(setup.source.get_kind() == 'local') - setup.source.stage(setup.context.builddir) - assert(os.path.exists(os.path.join(setup.context.builddir, 'file.txt'))) - assert(os.path.exists(os.path.join(setup.context.builddir, 'subdir', 'anotherfile.txt'))) +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'directory')) +def test_stage_directory(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + checkoutdir = os.path.join(str(tmpdir), "checkout") + + # Track, fetch, build, checkout + result = cli.run(project=project, args=['track', 'target.bst']) + assert result.exit_code == 0 + result = cli.run(project=project, args=['fetch', 'target.bst']) + assert result.exit_code == 0 + result = cli.run(project=project, args=['build', 'target.bst']) + assert result.exit_code == 0 + result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) + assert result.exit_code == 0 + + # Check that the checkout contains the expected file and directory and other file + assert(os.path.exists(os.path.join(checkoutdir, 'file.txt'))) + assert(os.path.exists(os.path.join(checkoutdir, 'subdir', 'anotherfile.txt'))) diff --git a/tests/sources/local/basic/target.bst b/tests/sources/local/basic/target.bst index da336d9f6..1a55ce19a 100644 --- a/tests/sources/local/basic/target.bst +++ b/tests/sources/local/basic/target.bst @@ -1,4 +1,4 @@ -kind: pony +kind: import description: This is the pony sources: - kind: local diff --git a/tests/sources/local/directory/target.bst b/tests/sources/local/directory/target.bst index 179c3d9d5..a4e51e82a 100644 --- a/tests/sources/local/directory/target.bst +++ b/tests/sources/local/directory/target.bst @@ -1,4 +1,4 @@ -kind: pony +kind: import description: This is the pony sources: - kind: local |