James Ennis pushed to branch jennis/less_restrictive_pathways at BuildStream / buildstream
Commits:
- 
b5f79674
by James Ennis at 2018-11-15T17:23:10Z
14 changed files:
- tests/sources/local.py
- + tests/sources/local/basic/outside_file.txt
- tests/sources/local/basic/file.txt → tests/sources/local/basic/project/file.txt
- tests/sources/local/basic/project.conf → tests/sources/local/basic/project/project.conf
- tests/sources/local/basic/target.bst → tests/sources/local/basic/project/target.bst
- tests/sources/patch.py
- tests/sources/patch/basic/file_1.patch → tests/sources/patch/basic/outside.patch
- tests/sources/patch/basic/failure-empty-dir.bst → tests/sources/patch/basic/project/failure-empty-dir.bst
- tests/sources/patch/basic/failure-nonexistent-dir.bst → tests/sources/patch/basic/project/failure-nonexistent-dir.bst
- tests/sources/patch/basic/file.txt → tests/sources/patch/basic/project/file.txt
- + tests/sources/patch/basic/project/file_1.patch
- tests/sources/patch/basic/irregular.bst → tests/sources/patch/basic/project/irregular.bst
- tests/sources/patch/basic/project.conf → tests/sources/patch/basic/project/project.conf
- tests/sources/patch/basic/target.bst → tests/sources/patch/basic/project/target.bst
Changes:
| ... | ... | @@ -10,7 +10,7 @@ DATA_DIR = os.path.join( | 
| 10 | 10 |  )
 | 
| 11 | 11 |  | 
| 12 | 12 |  | 
| 13 | -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
 | |
| 13 | +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic', 'project'))
 | |
| 14 | 14 |  def test_missing_path(cli, tmpdir, datafiles):
 | 
| 15 | 15 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 16 | 16 |  | 
| ... | ... | @@ -24,7 +24,7 @@ def test_missing_path(cli, tmpdir, datafiles): | 
| 24 | 24 |      result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.MISSING_FILE)
 | 
| 25 | 25 |  | 
| 26 | 26 |  | 
| 27 | -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
 | |
| 27 | +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic', 'project'))
 | |
| 28 | 28 |  def test_non_regular_file_or_directory(cli, tmpdir, datafiles):
 | 
| 29 | 29 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 30 | 30 |      localfile = os.path.join(project, 'file.txt')
 | 
| ... | ... | @@ -42,7 +42,7 @@ def test_non_regular_file_or_directory(cli, tmpdir, datafiles): | 
| 42 | 42 |                                       LoadErrorReason.PROJ_PATH_INVALID_KIND)
 | 
| 43 | 43 |  | 
| 44 | 44 |  | 
| 45 | -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
 | |
| 45 | +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic', 'project'))
 | |
| 46 | 46 |  def test_valid_absolute_path(cli, tmpdir, datafiles):
 | 
| 47 | 47 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 48 | 48 |  | 
| ... | ... | @@ -60,6 +60,26 @@ def test_valid_absolute_path(cli, tmpdir, datafiles): | 
| 60 | 60 |      result.assert_success()
 | 
| 61 | 61 |  | 
| 62 | 62 |  | 
| 63 | +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
 | |
| 64 | +def test_invalid_absolute_path(cli, tmpdir, datafiles):
 | |
| 65 | +    project = os.path.join(datafiles.dirname, datafiles.basename, 'project')
 | |
| 66 | + | |
| 67 | +    with open(os.path.join(project, "target.bst"), 'r') as f:
 | |
| 68 | +        old_yaml = f.read()
 | |
| 69 | + | |
| 70 | +    outside_project = os.path.dirname(project)
 | |
| 71 | +    new_yaml = old_yaml.replace("file.txt",
 | |
| 72 | +                                os.path.abspath(os.path.join(outside_project, "outside_file.txt")))
 | |
| 73 | +    assert old_yaml != new_yaml
 | |
| 74 | + | |
| 75 | +    with open(os.path.join(project, "target.bst"), 'w') as f:
 | |
| 76 | +        f.write(new_yaml)
 | |
| 77 | + | |
| 78 | +    result = cli.run(project=project, args=['show', 'target.bst'])
 | |
| 79 | +    result.assert_main_error(ErrorDomain.LOAD,
 | |
| 80 | +                             LoadErrorReason.PROJ_PATH_INVALID)
 | |
| 81 | + | |
| 82 | + | |
| 63 | 83 |  @pytest.mark.datafiles(os.path.join(DATA_DIR, 'invalid-relative-path'))
 | 
| 64 | 84 |  def test_invalid_relative_path(cli, tmpdir, datafiles):
 | 
| 65 | 85 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| ... | ... | @@ -69,7 +89,7 @@ def test_invalid_relative_path(cli, tmpdir, datafiles): | 
| 69 | 89 |                               LoadErrorReason.PROJ_PATH_INVALID)
 | 
| 70 | 90 |  | 
| 71 | 91 |  | 
| 72 | -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
 | |
| 92 | +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic', 'project'))
 | |
| 73 | 93 |  def test_stage_file(cli, tmpdir, datafiles):
 | 
| 74 | 94 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 75 | 95 |      checkoutdir = os.path.join(str(tmpdir), "checkout")
 | 
| 1 | +This is a text file outside the project | 
| ... | ... | @@ -10,7 +10,7 @@ DATA_DIR = os.path.join( | 
| 10 | 10 |  )
 | 
| 11 | 11 |  | 
| 12 | 12 |  | 
| 13 | -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
 | |
| 13 | +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic', 'project'))
 | |
| 14 | 14 |  def test_missing_patch(cli, tmpdir, datafiles):
 | 
| 15 | 15 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 16 | 16 |  | 
| ... | ... | @@ -24,7 +24,7 @@ def test_missing_patch(cli, tmpdir, datafiles): | 
| 24 | 24 |      result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.MISSING_FILE)
 | 
| 25 | 25 |  | 
| 26 | 26 |  | 
| 27 | -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
 | |
| 27 | +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic', 'project'))
 | |
| 28 | 28 |  def test_non_regular_file_patch(cli, tmpdir, datafiles):
 | 
| 29 | 29 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 30 | 30 |  | 
| ... | ... | @@ -40,7 +40,7 @@ def test_non_regular_file_patch(cli, tmpdir, datafiles): | 
| 40 | 40 |                                       LoadErrorReason.PROJ_PATH_INVALID_KIND)
 | 
| 41 | 41 |  | 
| 42 | 42 |  | 
| 43 | -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
 | |
| 43 | +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic', 'project'))
 | |
| 44 | 44 |  def test_valid_absolute_path(cli, tmpdir, datafiles):
 | 
| 45 | 45 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 46 | 46 |  | 
| ... | ... | @@ -57,6 +57,25 @@ def test_valid_absolute_path(cli, tmpdir, datafiles): | 
| 57 | 57 |      result.assert_success()
 | 
| 58 | 58 |  | 
| 59 | 59 |  | 
| 60 | +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
 | |
| 61 | +def test_invalid_absolute_path(cli, tmpdir, datafiles):
 | |
| 62 | +    project = os.path.join(datafiles.dirname, datafiles.basename, 'project')
 | |
| 63 | +    outside_project = os.path.dirname(project)
 | |
| 64 | + | |
| 65 | +    with open(os.path.join(project, "target.bst"), 'r') as f:
 | |
| 66 | +        old_yaml = f.read()
 | |
| 67 | +    new_yaml = old_yaml.replace("file_1.patch",
 | |
| 68 | +                                os.path.abspath(os.path.join(outside_project, "outside.patch")))
 | |
| 69 | +    assert old_yaml != new_yaml
 | |
| 70 | + | |
| 71 | +    with open(os.path.join(project, "target.bst"), 'w') as f:
 | |
| 72 | +        f.write(new_yaml)
 | |
| 73 | + | |
| 74 | +    result = cli.run(project=project, args=['show', 'target.bst'])
 | |
| 75 | +    result.assert_main_error(ErrorDomain.LOAD,
 | |
| 76 | +                             LoadErrorReason.PROJ_PATH_INVALID)
 | |
| 77 | + | |
| 78 | + | |
| 60 | 79 |  @pytest.mark.datafiles(os.path.join(DATA_DIR, 'invalid-relative-path'))
 | 
| 61 | 80 |  def test_invalid_relative_path(cli, tmpdir, datafiles):
 | 
| 62 | 81 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| ... | ... | @@ -66,7 +85,7 @@ def test_invalid_relative_path(cli, tmpdir, datafiles): | 
| 66 | 85 |                               LoadErrorReason.PROJ_PATH_INVALID)
 | 
| 67 | 86 |  | 
| 68 | 87 |  | 
| 69 | -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
 | |
| 88 | +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic', 'project'))
 | |
| 70 | 89 |  def test_stage_and_patch(cli, tmpdir, datafiles):
 | 
| 71 | 90 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 72 | 91 |      checkoutdir = os.path.join(str(tmpdir), "checkout")
 | 
| ... | ... | @@ -82,7 +101,7 @@ def test_stage_and_patch(cli, tmpdir, datafiles): | 
| 82 | 101 |          assert(f.read() == 'This is text file with superpowers\n')
 | 
| 83 | 102 |  | 
| 84 | 103 |  | 
| 85 | -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
 | |
| 104 | +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic', 'project'))
 | |
| 86 | 105 |  def test_stage_file_nonexistent_dir(cli, tmpdir, datafiles):
 | 
| 87 | 106 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 88 | 107 |      checkoutdir = os.path.join(str(tmpdir), "checkout")
 | 
| ... | ... | @@ -93,7 +112,7 @@ def test_stage_file_nonexistent_dir(cli, tmpdir, datafiles): | 
| 93 | 112 |      result.assert_task_error(ErrorDomain.SOURCE, "patch-no-files")
 | 
| 94 | 113 |  | 
| 95 | 114 |  | 
| 96 | -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
 | |
| 115 | +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic', 'project'))
 | |
| 97 | 116 |  def test_stage_file_empty_dir(cli, tmpdir, datafiles):
 | 
| 98 | 117 |      project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
| 99 | 118 |      checkoutdir = os.path.join(str(tmpdir), "checkout")
 | 
| 1 | +diff --git a/file.txt b/file.txt
 | |
| 2 | +index a496efe..341ef26 100644
 | |
| 3 | +--- a/file.txt
 | |
| 4 | ++++ b/file.txt
 | |
| 5 | +@@ -1 +1 @@
 | |
| 6 | +-This is a text file
 | |
| 7 | ++This is text file with superpowers | 
