Ejemplo n.º 1
0
def test_render_nested():
    ws = TestSuite(workspace)
    test = ws.get_test("nested-thing")
    source, version = test.get_source_and_version()
    version = version['upstream']
    tm = test.get_template_stack()
    with tmpdir() as tmp:
        path = "%s/%s-%s" % (tmp, source, version)
        mkdir(path)
        tm.render(path)
        assert os.path.exists("%s/kruft" % (path))
Ejemplo n.º 2
0
def test_todo():
    ws = TestSuite(workspace)
    test = ws.get_test("todo-test")
    source, version = test.get_source_and_version()
    version = version['upstream']
    tm = test.get_template_stack()
    with tmpdir() as tmp:
        path = "%s/%s-%s" % (tmp, source, version)
        mkdir(path)
        tm.render(path)
        ret = test.run()
        assert ret == {}
Ejemplo n.º 3
0
def test_insane_compression_fails():
    pkgname = "pkgfoo"
    version = "2.0"
    debdir = "%s-%s" % (pkgname, version)

    with tmpdir() as tmp:
        with cd(tmp):
            mkdir(debdir)
            try:
                make_orig_tarball(".", pkgname, version, compression="asfasf")
                assert True is False
            except ValueError:
                assert True is True
Ejemplo n.º 4
0
def test_localdir_generation():
    pkgname = "pkgfoo"
    version = "2.0"
    debdir = "%s-%s" % (pkgname, version)
    compression = "bzip2"
    tarball = "%s_%s.orig.tar.bz2" % (pkgname, version)

    with tmpdir() as tmp:
        with cd(tmp):
            mkdir(debdir)
            assert not os.path.exists(tarball)
            make_orig_tarball(".", pkgname, version, compression=compression)
            assert os.path.exists(tarball)
Ejemplo n.º 5
0
def test_debian_shim_there():
    """
    Ensure the shim removes the Debian directory, if it exists, and it can be
    run over the same thing more then once.
    """
    with tmpdir() as tmp:
        debdir = "%s/debian" % (tmp)
        mkdir(debdir)
        assert os.path.exists(debdir)
        ds = DebianShim()
        ds.render(tmp)
        assert not os.path.exists(debdir)
        ds.render(tmp)
Ejemplo n.º 6
0
def test_run_all_the_things():
    """
    Test all the thingers.
    """
    ws = TestSuite(workspace)
    test = ws.get_test("cruft-empty-diff")
    source, version = test.get_source_and_version()
    version = version['upstream']

    tm = test.get_template_stack()
    with tmpdir() as tmp:
        path = "%s/%s-%s" % (tmp, source, version)
        mkdir(path)
        tm.render(path)
Ejemplo n.º 7
0
def test_templater():
    """
    Make sure we can render out templates correctly
    """
    ws = TestSuite(workspace)
    test = ws.get_test("cruft-empty-diff")
    source, version = test.get_source_and_version()
    version = version['upstream']

    tm = test.get_template_stack()
    with tmpdir() as tmp:
        path = "%s/%s-%s" % (tmp, source, version)
        mkdir(path)
        tm.render(path)
Ejemplo n.º 8
0
def test_upstream_shim():
    """
    Ensure we create a debian tarball thinger.
    """
    pkgname = "testpkg-name"
    version = "1.0"
    with tmpdir() as tmp:
        with cd(tmp):
            mkdir("%s-%s" % (pkgname, version))
        tmp += "/%s-%s" % (pkgname, version)
        uss = UpstreamShim(pkgname, version)
        uss.set_compression("gzip")
        uss.render(tmp)
        assert "%s/%s_%s.orig.tar.gz" % (tmp, pkgname, version)
        assert "%s/%s-%s" % (tmp, pkgname, version)
Ejemplo n.º 9
0
def test_debian_shim_there_two():
    """
    Ensure the Debian shim won't remove files other then the Debian/
    directory.
    """
    with tmpdir() as tmp:
        debdir = "%s/debian" % (tmp)
        testfd = "%s/foo" % (tmp)
        mkdir(debdir)
        open(testfd, "w").close()
        assert os.path.exists(debdir)
        assert os.path.exists(testfd)
        ds = DebianShim()
        ds.render(tmp)
        assert not os.path.exists(debdir)
        assert os.path.exists(testfd)
        ds.render(tmp)
Ejemplo n.º 10
0
def test_more_walk():
    """
    Ensure s'more basics in walking a directory, with an extention
    filter.
    """
    with tmpdir() as t:
        with cd(t):
            mkdir("foo")
            mkdir("bar")
            mkdir("baz")

            valid_targets = ["./foo/bar.target", "./bar/foo.target", "./kruft.target"]

            invalid_targets = ["./foo/bar", "./baz/foo", "./kruft"]
            invalid_cmp = list(invalid_targets)

            for target in valid_targets + invalid_targets:
                touch(target)

            for entry in dir_walk("./", xtn="target"):
                if entry in valid_targets:
                    valid_targets.remove(entry)
                if entry in invalid_targets:
                    invalid_targets.remove(entry)

        assert valid_targets == []
        assert invalid_targets == invalid_cmp
Ejemplo n.º 11
0
def make_and_check_tarball(testname, rundir, upname, upversion, compression,
                           visitor, visit_open=True):
    """Create, check and clean up a tarball (test utility)

    Utility for setting up a dir, compile a tarball from a resource path,
    opening the tarball and passing it to vistor.

    testname is used to create a unique name for the test.  The
    compression is also used for this purpose, so multiple tests can
    share the same "testname" as long as the compression differs.

    rundir, upname, upversion and compression are passed (as is) to
    make_orig_tarball.

    The tarball passed to visitor may not be seekable and should be
    checked inorder.
    """

    testdir = "%s-%s" % (testname, compression)
    xtn = compression
    if xtn == "gzip":
        xtn = "gz"
    elif xtn == "bzip2":
        xtn = "bz2"

    rundir = abspath(rundir)

    with tmpdir() as tmp:
        with cd(tmp):
            mkdir(testdir)

            make_orig_tarball(rundir, upname, upversion,
                              compression=compression, outputdir=testdir)
            tarname = "%s_%s.orig.tar.%s" % (upname, upversion, xtn)
            path = os.path.join(testdir, tarname)
            if visit_open:
                with open_compressed_tarball(path, compression) as tar:
                    visitor(tar)
            else:
                visitor(path)
Ejemplo n.º 12
0
def test_basic_walk():
    """
    Test to make sure we can walk a directory.
    """
    with tmpdir() as t:
        with cd(t):
            mkdir("foo")
            mkdir("bar")
            mkdir("baz")

            targets = ["./foo/bar.target", "./foo/bar", "./bar/foo.target", "./baz/foo"]

            for target in targets:
                touch(target)

            for entry in dir_walk("./"):
                assert entry in targets
                targets.remove(entry)

        assert targets == []
Ejemplo n.º 13
0
def _alter_root_add_unexpected_file(rootdir):
    d = os.path.join(rootdir, "usr/random")
    mkdir(d)
    f = os.path.join(d, "place")
    with open(f, "w") as fd:
        fd.write("Not supposed to bere!")
Ejemplo n.º 14
0
def _alter_root_break_type(rootdir):
    cpyf = os.path.join(rootdir, "usr/share/doc/foo/copyright")
    rm(cpyf)
    mkdir(cpyf)
Ejemplo n.º 15
0
    def run(self, verbose=False):
        templates = self._context['templates'][:]
        templates.reverse()

        for template in templates:
            template = "%s.json" % (template)

            try:
                context = self._workspace._look_up('contexts', template)
                context = load_config(context)
                self.set_global_context(context)
            except NoSuchCallableError as e:
                pass

        self._run_hook("init")

        if "todo" in self._context:
            return {}

        source, version = self.get_source_and_version()
        version = version['upstream']
        tm = self.get_template_stack()
        with tmpdir() as tmp:
            self.path = "%s/%s-%s" % (tmp, source, version)
            path = self.path
            mkdir(path)
            self._run_hook("tmpdir", path=tmp)
            tm.render(path)

            self._run_hook("pre-build", path=path)
            self._run_builds()
            self._run_hook("post-build", path=path)

            self._run_hook("pre-check", path=path)
            self._run_checks()
            self._run_hook("post-check", path=path)

            results = {}
            for checker in self._context['checkers']:
                pristine = "%s/%s" % (self._test_path, checker)
                output = "%s/%s" % (tmp, checker)
                if os.path.exists(pristine):
                    # OK, let's verify
                    if os.path.exists(output):
                        with open("/dev/null", "w") as null:
                            if diff(pristine, output,
                                    output_fd=null):
                                results[checker] = "passed"
                            else:
                                results[checker] = "failed"
                                if verbose:
                                    print "================================"
                                    print "Checker match failure:"
                                    print "  -> %s" % (self.name)
                                    print "  -> %s" % (checker)
                                    print "--------------------------------"
                                    diff(pristine, output)
                                    print "================================"
                    else:
                        results[checker] = "no-output"
                else:
                    results[checker] = "no-pristine"
            self._run_hook("finally", path=path)
        return results