diff options
| author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-12-29 19:39:35 -0500 |
|---|---|---|
| committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-01-01 19:44:53 +0900 |
| commit | c6df92fcbec1300334cdb1a79fdfa633fb3385fb (patch) | |
| tree | 4ecce9db0109df4c0340c65119c71c19ba6e84bf /tests/sources/patch.py | |
| parent | fbdb5118f6322cf2f5e8bdb24bc7c5a8fdd374bc (diff) | |
| download | buildstream-c6df92fcbec1300334cdb1a79fdfa633fb3385fb.tar.gz | |
tests/sources: Use new error checking tools for source tests
Also added a test case for the `patch` plugin which checks for graceful
failure when the specified patch file is not a regular file (but a block
device or a named pipe instead).
Diffstat (limited to 'tests/sources/patch.py')
| -rw-r--r-- | tests/sources/patch.py | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/tests/sources/patch.py b/tests/sources/patch.py index 8a1b9bf42..2f23fd5dd 100644 --- a/tests/sources/patch.py +++ b/tests/sources/patch.py @@ -1,8 +1,7 @@ import os import pytest -from buildstream._pipeline import PipelineError -from buildstream import SourceError +from buildstream._exceptions import ErrorDomain from tests.testutils import cli DATA_DIR = os.path.join( @@ -22,9 +21,21 @@ def test_missing_patch(cli, tmpdir, datafiles): result = cli.run(project=project, args=[ 'show', 'target.bst' ]) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, SourceError) + result.assert_main_error(ErrorDomain.SOURCE, 'patch-no-exist') + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) +def test_non_regular_file_patch(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + + # Add a fifo, that's not a regular file, should cause explosions + patch_path = os.path.join(datafiles.dirname, datafiles.basename, 'irregular_file.patch') + os.mkfifo(patch_path) + + result = cli.run(project=project, args=[ + 'show', 'irregular.bst' + ]) + result.assert_main_error(ErrorDomain.SOURCE, "patch-not-a-file") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) @@ -34,9 +45,9 @@ def test_stage_and_patch(cli, tmpdir, datafiles): # Build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Test the file.txt was patched and changed with open(os.path.join(checkoutdir, 'file.txt')) as f: @@ -50,9 +61,8 @@ def test_stage_file_nonexistent_dir(cli, tmpdir, datafiles): # 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) + result.assert_main_error(ErrorDomain.PIPELINE, None) + result.assert_task_error(ErrorDomain.SOURCE, "patch-no-files") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) @@ -62,9 +72,8 @@ def test_stage_file_empty_dir(cli, tmpdir, datafiles): # 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) + result.assert_main_error(ErrorDomain.PIPELINE, None) + result.assert_task_error(ErrorDomain.SOURCE, "patch-no-files") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'separate-patch-dir')) @@ -74,9 +83,9 @@ def test_stage_separate_patch_dir(cli, tmpdir, datafiles): # Track, fetch, build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Test the file.txt was patched and changed with open(os.path.join(checkoutdir, 'test-dir', 'file.txt')) as f: @@ -90,9 +99,9 @@ def test_stage_multiple_patches(cli, tmpdir, datafiles): # Track, fetch, build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Test the file.txt was patched and changed with open(os.path.join(checkoutdir, 'file.txt')) as f: @@ -106,9 +115,9 @@ def test_patch_strip_level(cli, tmpdir, datafiles): # Track, fetch, build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Test the file.txt was patched and changed with open(os.path.join(checkoutdir, 'file.txt')) as f: |
