diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-04 18:17:57 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-04 18:18:56 +0900 |
commit | 139b7d98178100954c64cb788dbd4a01549f75ec (patch) | |
tree | bfad00434fd350e4bb3f2f9c0c64f33962284a62 /tests/sources | |
parent | 46ff3182e7036eb1acf72e2ec991ee043462a316 (diff) | |
download | buildstream-139b7d98178100954c64cb788dbd4a01549f75ec.tar.gz |
tests/sources/patch.py: Converted to use CLI fixtures
Diffstat (limited to 'tests/sources')
-rw-r--r-- | tests/sources/patch.py | 171 | ||||
-rw-r--r-- | tests/sources/patch/basic/failure-empty-dir.bst | 2 | ||||
-rw-r--r-- | tests/sources/patch/basic/failure-nonexistent-dir.bst | 2 | ||||
-rw-r--r-- | tests/sources/patch/basic/target.bst | 2 | ||||
-rw-r--r-- | tests/sources/patch/different-strip-level/target.bst | 2 | ||||
-rw-r--r-- | tests/sources/patch/multiple-patches/target.bst | 2 | ||||
-rw-r--r-- | tests/sources/patch/separate-patch-dir/files/test-dir/file.txt (renamed from tests/sources/patch/separate-patch-dir/test-dir/file.txt) | 0 | ||||
-rw-r--r-- | tests/sources/patch/separate-patch-dir/target.bst | 4 |
8 files changed, 82 insertions, 103 deletions
diff --git a/tests/sources/patch.py b/tests/sources/patch.py index cca2c312a..8a1b9bf42 100644 --- a/tests/sources/patch.py +++ b/tests/sources/patch.py @@ -1,10 +1,9 @@ import os import pytest +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__)), @@ -13,124 +12,104 @@ 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) - patch_sources = [source for source in setup.sources if source.get_kind() == 'patch'] - assert(len(patch_sources) == 1) - - -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) -def test_preflight(tmpdir, datafiles): - setup = Setup(datafiles, 'target.bst', tmpdir) - patch_source = [source for source in setup.sources if source.get_kind() == 'patch'][0] - - # Just expect that this passes without throwing any exception - patch_source.preflight() - - -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) -def test_preflight_fail(tmpdir, datafiles): - setup = Setup(datafiles, 'target.bst', tmpdir) - patch_source = [source for source in setup.sources if source.get_kind() == 'patch'][0] +def test_missing_patch(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_1.patch') os.remove(localfile) - # Expect a preflight error - with pytest.raises(SourceError): - patch_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_unique_key(tmpdir, datafiles): - setup = Setup(datafiles, 'target.bst', tmpdir) - patch_source = [source for source in setup.sources if source.get_kind() == 'patch'][0] - - # Get the unique key - unique_key = patch_source.get_unique_key() - - # No easy way to test this, let's just check that the - # returned 'thing' is an array of tuples and the first element - # of the first tuple is the filename, and the second is not falsy - assert(isinstance(unique_key, list)) - filename, digest, strip_level = unique_key - assert(filename == 'file_1.patch') - assert(digest) - assert(strip_level == 1) - - -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) -def test_stage_file(tmpdir, datafiles): - setup = Setup(datafiles, 'target.bst', tmpdir) - - for source in setup.sources: - source.preflight() - source.stage(setup.context.builddir) - with open(os.path.join(setup.context.builddir, 'file.txt')) as f: +def test_stage_and_patch(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + checkoutdir = os.path.join(str(tmpdir), "checkout") + + # Build, checkout + 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 + + # Test the file.txt was patched and changed + with open(os.path.join(checkoutdir, 'file.txt')) as f: assert(f.read() == 'This is text file with superpowers\n') @pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) -def test_stage_file_nonexistent_dir(tmpdir, datafiles): - setup = Setup(datafiles, 'failure-nonexistent-dir.bst', tmpdir) - patch_sources = [source for source in setup.sources if source.get_kind() == 'patch'] - assert(len(patch_sources) == 1) +def test_stage_file_nonexistent_dir(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + checkoutdir = os.path.join(str(tmpdir), "checkout") - for source in setup.sources: - source.preflight() - if source.get_kind() == 'patch': - with pytest.raises(SourceError): - source.stage(setup.context.builddir) + # Fails at build time because it tries to patch into a non-existing directory + result = cli.run(project=project, args=['build', 'failure-nonexistent-dir.bst']) + assert result.exit_code != 0 + assert result.exception + assert isinstance(result.exception, PipelineError) @pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) -def test_stage_file_empty_dir(tmpdir, datafiles): - setup = Setup(datafiles, 'failure-empty-dir.bst', tmpdir) - patch_sources = [source for source in setup.sources if source.get_kind() == 'patch'] - assert(len(patch_sources) == 1) +def test_stage_file_empty_dir(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + checkoutdir = os.path.join(str(tmpdir), "checkout") - for source in setup.sources: - source.preflight() - if source.get_kind() == 'patch': - with pytest.raises(SourceError): - source.stage(setup.context.builddir) + # Fails at build time because it tries to patch with nothing else staged + result = cli.run(project=project, args=['build', 'failure-empty-dir.bst']) + assert result.exit_code != 0 + assert result.exception + assert isinstance(result.exception, PipelineError) @pytest.mark.datafiles(os.path.join(DATA_DIR, 'separate-patch-dir')) -def test_stage_separate_patch_dir(tmpdir, datafiles): - setup = Setup(datafiles, 'target.bst', tmpdir) - patch_sources = [source for source in setup.sources if source.get_kind() == 'patch'] - assert(len(patch_sources) == 1) - - for source in setup.sources: - source.preflight() - source.stage(setup.context.builddir) - with open(os.path.join(setup.context.builddir, 'file.txt')) as f: +def test_stage_separate_patch_dir(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=['build', 'target.bst']) + assert result.exit_code == 0 + result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) + assert result.exit_code == 0 + + # Test the file.txt was patched and changed + with open(os.path.join(checkoutdir, 'test-dir', 'file.txt')) as f: assert(f.read() == 'This is text file in a directory with superpowers\n') @pytest.mark.datafiles(os.path.join(DATA_DIR, 'multiple-patches')) -def test_stage_multiple_patches(tmpdir, datafiles): - setup = Setup(datafiles, 'target.bst', tmpdir) - patch_sources = [source for source in setup.sources if source.get_kind() == 'patch'] - assert(len(patch_sources) == 2) - - for source in setup.sources: - source.preflight() - source.stage(setup.context.builddir) - with open(os.path.join(setup.context.builddir, 'file.txt')) as f: +def test_stage_multiple_patches(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=['build', 'target.bst']) + assert result.exit_code == 0 + result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) + assert result.exit_code == 0 + + # Test the file.txt was patched and changed + with open(os.path.join(checkoutdir, 'file.txt')) as f: assert(f.read() == 'This is text file with more superpowers\n') @pytest.mark.datafiles(os.path.join(DATA_DIR, 'different-strip-level')) -def test_patch_strip_level(tmpdir, datafiles): - setup = Setup(datafiles, 'target.bst', tmpdir) - patch_sources = [source for source in setup.sources if source.get_kind() == 'patch'] - assert(len(patch_sources) == 1) - - for source in setup.sources: - source.preflight() - source.stage(setup.context.builddir) - with open(os.path.join(setup.context.builddir, 'file.txt')) as f: +def test_patch_strip_level(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=['build', 'target.bst']) + assert result.exit_code == 0 + result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) + assert result.exit_code == 0 + + # Test the file.txt was patched and changed + with open(os.path.join(checkoutdir, 'file.txt')) as f: assert(f.read() == 'This is text file with superpowers\n') diff --git a/tests/sources/patch/basic/failure-empty-dir.bst b/tests/sources/patch/basic/failure-empty-dir.bst index 42fd33c19..b22af27fb 100644 --- a/tests/sources/patch/basic/failure-empty-dir.bst +++ b/tests/sources/patch/basic/failure-empty-dir.bst @@ -1,4 +1,4 @@ -kind: pony +kind: import description: This is also the pony sources: - kind: patch diff --git a/tests/sources/patch/basic/failure-nonexistent-dir.bst b/tests/sources/patch/basic/failure-nonexistent-dir.bst index 90270f1e3..8fd593dec 100644 --- a/tests/sources/patch/basic/failure-nonexistent-dir.bst +++ b/tests/sources/patch/basic/failure-nonexistent-dir.bst @@ -1,4 +1,4 @@ -kind: pony +kind: import description: This is also the pony sources: - kind: patch diff --git a/tests/sources/patch/basic/target.bst b/tests/sources/patch/basic/target.bst index ab86e389f..913371d47 100644 --- a/tests/sources/patch/basic/target.bst +++ b/tests/sources/patch/basic/target.bst @@ -1,4 +1,4 @@ -kind: manual +kind: import description: This is the pony sources: - kind: local diff --git a/tests/sources/patch/different-strip-level/target.bst b/tests/sources/patch/different-strip-level/target.bst index d893c9edd..c8ea19a12 100644 --- a/tests/sources/patch/different-strip-level/target.bst +++ b/tests/sources/patch/different-strip-level/target.bst @@ -1,4 +1,4 @@ -kind: pony +kind: import description: This is the pony sources: - kind: local diff --git a/tests/sources/patch/multiple-patches/target.bst b/tests/sources/patch/multiple-patches/target.bst index 080ee2c0d..4665e7d0d 100644 --- a/tests/sources/patch/multiple-patches/target.bst +++ b/tests/sources/patch/multiple-patches/target.bst @@ -1,4 +1,4 @@ -kind: pony +kind: import description: This is the pony sources: - kind: local diff --git a/tests/sources/patch/separate-patch-dir/test-dir/file.txt b/tests/sources/patch/separate-patch-dir/files/test-dir/file.txt index 425911a7f..425911a7f 100644 --- a/tests/sources/patch/separate-patch-dir/test-dir/file.txt +++ b/tests/sources/patch/separate-patch-dir/files/test-dir/file.txt diff --git a/tests/sources/patch/separate-patch-dir/target.bst b/tests/sources/patch/separate-patch-dir/target.bst index 70ae20b70..796c1316c 100644 --- a/tests/sources/patch/separate-patch-dir/target.bst +++ b/tests/sources/patch/separate-patch-dir/target.bst @@ -1,8 +1,8 @@ -kind: pony +kind: import description: This is the pony sources: - kind: local - path: test-dir + path: files - kind: patch path: file_1.patch directory: test-dir |