Exemple #1
0
def test_subst_command_both(tmpdir, capsys):
    """
    Test subst_command() with dryrun True and quiet True.
    """
    pytest.debug_func()
    with U.Chdir(tmpdir.strpath):
        v = optparse.Values({'dryrun': True, 'quiet': True, 'cmd': 'ls %'})
        a = ['a.pl', 'b.pl', 'c.pl']
        exp = "".join(["would do 'ls %s'\n" % x for x in a])
        U.safe_unlink(a)

        fx.subst_command(v, a)
        assert exp in "".join(capsys.readouterr())
Exemple #2
0
    def test_SubstCommand_both(self):
        """
        Test SubstCommand() with dryrun True and quiet True.
        """
        with U.Chdir(self.testdir):
            v = optparse.Values({'dryrun': True, 'quiet': True, 'cmd': 'ls %'})
            a = ['a.pl', 'b.pl', 'c.pl']
            exp = "".join(["would do 'ls %s'\n" % x for x in a])
            U.safe_unlink(a)

            with th.StdoutExcursion() as getval:
                fx.SubstCommand(v, a)
                actual = getval()

            self.assertEq(exp, actual)
Exemple #3
0
def test_help(tmpdir):
    """
    Run 'pytool help'. Verify that the output is correct
    """
    pytest.debug_func()
    with U.Chdir(tmpdir.strpath):
        outputs = ["testtool", "testtool.py", "xyzzy", "xyzzy.py"]
        U.safe_unlink(outputs)
        cmd = pexpect.which("pytool")
        S = pexpect.spawn("{} help".format(cmd))
        which = S.expect([r"Are you sure\? >",
                          "Error:",
                          pexpect.EOF])
        if which == 0:
            S.sendline("no")
            S.expect(pexpect.EOF)
            pytest.fail("should not have asked about overwriting")
        elif which == 1:
            print S.before + S.after
            pytest.fail("unexpected exception")

        for file in outputs:
            assert not os.path.exists(file)
Exemple #4
0
    def fl_edit_ok(self, eopt='', iopt='', files=0, inp=[], exp=[]):
        """
        Common code for all the test_fl_edit_* routines
        """
        fl = []
        for idx in range(files):
            (fd, fp) = tempfile.mkstemp(dir=self.testdir)
            os.close(fd)
            fl.append(fp)
            util.writefile(fp, inp)

        suffix = 'original'
        with util.Chdir(self.testdir):
            cmd = "fl edit "
            if eopt != '':
                cmd += '-e "%s" ' % eopt
            if iopt != '':
                cmd += '-i %s ' % iopt
                suffix = iopt
            if 0 < len(fl):
                cmd += " ".join(fl)
            result = pexpect.run(cmd)

            self.assertTrue(result == "",
                            "Expected '%s' to be empty" % result)
            for fp in fl:
                forig = fp + "." + suffix
                self.assertTrue(util.exists(forig),
                                "Expected %s to exist" % forig)
                self.assertTrue("foo four five foo" in util.contents(forig),
                                "Contents of %s have changed" % forig)
                self.assertTrue(util.exists(fp),
                                "Expected %s to exist" % fp)
                self.assertEq(exp, util.contents(fp))

            for fp in fl:
                util.safe_unlink(fp)