Exemple #1
0
def test_url_patch(mock_patch_stage, filename, sha256, archive_sha256, config):
    # Make a patch object
    url = 'file://' + filename
    s = Spec('patch').concretized()
    patch = spack.patch.UrlPatch(s.package,
                                 url,
                                 sha256=sha256,
                                 archive_sha256=archive_sha256)

    # make a stage
    with Stage(url) as stage:  # TODO: url isn't used; maybe refactor Stage
        stage.mirror_path = mock_patch_stage

        mkdirp(stage.source_path)
        with working_dir(stage.source_path):
            # write a file to be patched
            with open('foo.txt', 'w') as f:
                f.write("""\
first line
second line
""")
            # write the expected result of patching.
            with open('foo-expected.txt', 'w') as f:
                f.write("""\
zeroth line
first line
third line
""")
        # apply the patch and compare files
        patch.fetch()
        patch.apply(stage)
        patch.clean()

        with working_dir(stage.source_path):
            assert filecmp.cmp('foo.txt', 'foo-expected.txt')
Exemple #2
0
def test_url_patch(mock_patch_stage, filename, sha256, archive_sha256):
    # Make a patch object
    url = 'file://' + filename
    pkg = spack.repo.get('patch')
    patch = spack.patch.UrlPatch(pkg,
                                 url,
                                 sha256=sha256,
                                 archive_sha256=archive_sha256)

    # make a stage
    with Stage(url) as stage:  # TODO: url isn't used; maybe refactor Stage
        stage.mirror_path = mock_patch_stage

        mkdirp(stage.source_path)
        with working_dir(stage.source_path):
            write_file("foo.txt", file_to_patch)
            write_file("foo-expected.txt", expected_patch_result)

        # apply the patch and compare files
        patch.fetch()
        patch.apply(stage)
        patch.clean()

        with working_dir(stage.source_path):
            assert filecmp.cmp('foo.txt', 'foo-expected.txt')
Exemple #3
0
def test_url_patch(mock_stage, filename, sha256, archive_sha256):
    # Make a patch object
    url = 'file://' + filename
    pkg = spack.repo.get('patch')
    patch = spack.patch.UrlPatch(pkg,
                                 url,
                                 sha256=sha256,
                                 archive_sha256=archive_sha256)

    # make a stage
    with Stage(url) as stage:  # TODO: url isn't used; maybe refactor Stage
        # TODO: there is probably a better way to mock this.
        stage.mirror_path = mock_stage  # don't disrupt the spack install

        # Fake a source path and ensure the directory exists
        with working_dir(stage.path):
            mkdirp(spack.stage._source_path_subdir)

        with working_dir(stage.source_path):
            # write a file to be patched
            with open('foo.txt', 'w') as f:
                f.write("""\
first line
second line
""")
            # write the expected result of patching.
            with open('foo-expected.txt', 'w') as f:
                f.write("""\
zeroth line
first line
third line
""")
        # apply the patch and compare files
        patch.fetch(stage)
        patch.apply(stage)
        patch.clean()

        with working_dir(stage.source_path):
            assert filecmp.cmp('foo.txt', 'foo-expected.txt')