示例#1
0
    def test_SubstRename_quiet(self):
        """
        Test SubstRename() with dryrun False and quiet True.
        """
        with U.Chdir(self.testdir):
            arglist = ['a.pl', 'b.pl', 'c.pl']
            for a in arglist:
                U.touch(a)
            expected = "".join(['rename %s.pl %s.xyzzy\n' % (x, x) for x in
                                [q.replace('.pl', '') for q in arglist]])
            exp = [re.sub('.pl', '.xyzzy', x) for x in arglist]
            v = optparse.Values({'dryrun': False, 'quiet': True,
                                 'edit': 's/.pl/.xyzzy'})

            with th.StdoutExcursion() as getval:
                fx.SubstRename(v, arglist)
                actual = getval()

            self.assertEq(expected, actual)

            q = glob.glob('*.pl')
            q.sort()
            self.assertEq([], q)

            q = glob.glob('*.xyzzy')
            q.sort()
            self.assertEq(exp, q)
示例#2
0
def test_subst_rename_quiet(tmpdir, capsys):
    """
    Test subst_rename() with dryrun False and quiet True.
    """
    pytest.debug_func()
    with U.Chdir(tmpdir.strpath):
        arglist = ['a.pl', 'b.pl', 'c.pl']
        for a in arglist:
            U.touch(a)
        expected = "".join(['rename %s.pl %s.xyzzy\n' % (x, x) for x in
                            [q.replace('.pl', '') for q in arglist]])
        exp = [re.sub('.pl', '.xyzzy', x) for x in arglist]
        v = optparse.Values({'dryrun': False, 'quiet': True,
                             'edit': 's/.pl/.xyzzy'})

        fx.subst_rename(v, arglist)
        assert expected in " ".join(capsys.readouterr())

        q = glob.glob('*.pl')
        q.sort()
        assert [] == q

        q = glob.glob('*.xyzzy')
        q.sort()
        assert exp == q
示例#3
0
 def test_contents_empty(self):
     """
     Calling contents on an empty file should return an empty list
     """
     with U.Chdir(self.testdir):
         U.touch("empty_file")
         z = U.contents("empty_file")
     self.assertEqual([], z)
示例#4
0
 def setUp(self):
     """
     Set up for each test in the suite.
     """
     if os.path.isdir(self.testdir):
         self.tearDown()
     os.makedirs(U.pj(self.testdir, 'sub'))
     for fp in self.testfiles:
         U.touch(fp)
示例#5
0
 def test_touch_str(self):
     """
     Calling touch() with a string, setting the current time
     """
     with U.Chdir(self.testdir):
         now = int(time.time())
         filename = "pines"
         U.touch(filename)
         self.assertTrue(os.path.exists(filename))
         s = os.stat(filename)
         self.assertEqual(now, s[stat.ST_ATIME])
         self.assertEqual(now, s[stat.ST_MTIME])
示例#6
0
 def test_touch_str_times(self):
     """
     Calling touch() with a string, setting some other time
     """
     with U.Chdir(self.testdir):
         now = int(time.time())
         tt = (now-17, now+42)
         filename = "pines"
         U.touch(filename, tt)
         self.assertTrue(os.path.exists(filename))
         s = os.stat(filename)
         self.assertEqual(tt[0], s[stat.ST_ATIME])
         self.assertEqual(tt[1], s[stat.ST_MTIME])
示例#7
0
def test_subst_command_quiet(tmpdir, capsys):
    """
    Test subst_command() with dryrun False and quiet True.
    """
    pytest.debug_func()
    with U.Chdir(tmpdir.strpath):
        v = optparse.Values({'dryrun': False, 'quiet': True,
                             'cmd': 'ls %'})
        a = ['a.pl', 'b.pl', 'c.pl']
        exp = "".join(['%s\n' % x for x in a])
        U.touch(a)

        fx.subst_command(v, a)
        assert exp in " ".join(capsys.readouterr())
示例#8
0
 def test_touch_list(self):
     """
     Routine touch() should create the file if it does not exist and update
     its atime and mtime if it does. It takes a string or list.
     """
     with U.Chdir(self.testdir):
         now = int(time.time())
         flist = ["jabberwocky", "philodendron", "mcguffin"]
         U.touch(flist)
         for fn in flist:
             self.assertTrue(os.path.exists(fn))
             s = os.stat(fn)
             self.assertEqual(now, s[stat.ST_ATIME])
             self.assertEqual(now, s[stat.ST_MTIME])
示例#9
0
    def test_editfile_empty(self):
        """
        fl.editfile('emptyfile', 's', 'foo', 'bar', None)
         => rename emptyfile emptyfile.original, both empty
        """
        fpath = U.pj(self.testdir, 'emptyfile')
        forig = fpath + ".original"
        U.touch(fpath)

        fl.editfile(fpath, 's', 'foo', 'bar', None)

        self.assertEq(True, U.exists(fpath))
        self.assertEq(True, U.exists(forig))
        self.assertEq([], U.contents(fpath))
        self.assertEq([], U.contents(forig))
示例#10
0
    def test_SubstCommand_quiet(self):
        """
        Test SubstCommand() with dryrun False and quiet True.
        """
        with U.Chdir(self.testdir):
            v = optparse.Values({'dryrun': False, 'quiet': True,
                                 'cmd': 'ls %'})
            a = ['a.pl', 'b.pl', 'c.pl']
            exp = "".join(['%s\n' % x for x in a])
            U.touch(a)

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

            self.assertEq(exp, actual)
示例#11
0
 def test_touch_list_times(self):
     """
     Routine touch() should create the file if it does not exist and update
     its atime and mtime if it does. It takes a string or list. It also
     takes an optional second argument containing a tuple with the atime and
     mtime we want to set on the target file(s)
     """
     with U.Chdir(self.testdir):
         now = int(time.time())
         tt = (now+3, now-4)
         flist = ["jabberwocky", "philodendron", "mcguffin"]
         U.touch(flist, tt)
         for fn in flist:
             self.assertTrue(os.path.exists(fn))
             s = os.stat(fn)
             self.assertEqual(tt[0], s[stat.ST_ATIME])
             self.assertEqual(tt[1], s[stat.ST_MTIME])
示例#12
0
def gtxtest_setup_hldirs(tmpdir, hooks=[], mklinks=[]):
    """
    Create the hook and link directories and maybe set up some links
    """
    if isinstance(tmpdir, py._path.local.LocalPath):
        tdname = tmpdir.strpath
    else:
        tdname = tmpdir
    bn_d = {}
    bn_d['hookdir'] = os.path.join(tdname, "hookdir")
    os.mkdir(bn_d['hookdir'])
    bn_d['linkdir'] = os.path.join(tdname, "linkdir")
    os.mkdir(bn_d['linkdir'])
    for hook in hooks:
        bn_d[hook] = {}
        bn_d[hook]['hook'] = os.path.join(bn_d['hookdir'], hook)
        bn_d[hook]['link'] = os.path.join(bn_d['linkdir'], hook)
        U.touch(bn_d[hook]['hook'])
        if hook in mklinks:
            os.symlink(bn_d[hook]['hook'], bn_d[hook]['link'])
    return bn_d