Exemple #1
0
 def _test_get_files_simple(self):
     #"""Retrieve files in basedir properly."""
     fileset = ('bar', 'far', 'tar')
     subdir = Path(self.dir, 'get_files_simple')
     subdir.mkdir()
     obj = Initer(files=(subdir,), pattern='*')
     # no files
     ofiles = obj.get_files()
     #print 'ofiles =', repr(ofiles), vars(ofiles)
     self.assertEqual(list(obj.get_files(('*',))), [])
     for n in fileset:
         f = subdir + n #V['basedir'] + n  # subdir + n
         logging.error('n %s = f %s', n, f)
         f.open('w').close()
     # test simple glob
     result = obj.get_files()
     #print 'results =', repr(result), vars(result)
     self.assertEqual(sorted(result), list(fileset))
     # test single file
     self.assertEqual(list(obj.get_files(('bar',))),
                      ['bar'])
     # test single file, no glob
     obj.noglob = True
     self.assertEqual(list(obj.get_files(('tar',))),
                      ['tar'])
     obj.noglob = False
     # test simple file tuple, with glob
     self.assertEqual(sorted(obj.get_files(('bar', 'tar'))),
                      ['bar',
                       'tar'])
     # test glob file tuple, with glob
     self.assertEqual(sorted(obj.get_files(('bar', 't*'))),
                      ['bar',
                       'tar'])
Exemple #2
0
 def test_glob(self):
     d = Path(self.tpath, 'glob.d')
     d.mkdir()
     for i in range(3):
         (d + str(i)).open()
     self.assertEqual([f.basename for f in sorted(d.glob('[0-9]'))],
                      ['0', '1', '2'])
Exemple #3
0
 def test__add_(self):
     f1 = Path('etc')
     f2 = Path('etc')
     f3 = Path('etc', 'etc')
     self.assertEqual(f1 + f2, f3)
     self.assertEqual(f1 + 'etc', f3)
     self.assertEqual('etc' + f1, f3)
Exemple #4
0
 def test__sub_(self):
     f1 = Path('etc', 'etc')
     f2 = Path('etc')
     f3 = Path('etc', 'len')
     self.assertEqual(f1 - f2, f2)
     self.assertEqual(f3 - f2, 'len')
     self.assertEqual(f2 - f1, os.pardir)
Exemple #5
0
 def test__lt_(self):
     f1 = Path('etc')
     f2 = Path('len')
     self.assertTrue(f1 < f2)
     self.assertTrue(f1 < 'len')
     self.assertFalse(f1 == f2)
     self.assertFalse(f1 > 'len')
Exemple #6
0
 def test_join(self):
     #"""Ensure that join() method returns proper values."""
     obj = Initer()
     self.assertEqual(obj.join('foobar'),
                      Path(self.dir, 'foobar'))
     self.assertEqual(obj.join('xyzzy', 'foobar'),
                      Path(self.dir, 'xyzzy', 'foobar'))
Exemple #7
0
 def testcheck_candidate(self):
     obj = Iterator()
     self.assertTrue(obj.check_candidate(Path("hello")))
     obj = Iterator(pattern="*.py")
     self.assertTrue(obj.check_candidate(Path("hello.py")))
     self.assertFalse(obj.check_candidate(Path("hello.c")))
     self.assertRaises(AttributeError, obj.check_candidate, ('hello.py', ))
Exemple #8
0
 def test_ctime(self):
     import time
     p = Path(self.tpath, 'ctime.f')
     p.open('w')
     now = int(time.time())
     os.utime(str(p), (now, now))
     self.assertEqual(p.ctime, now)
Exemple #9
0
 def test_items_none_defaults(self):
     e = Exclusions(('1', '2', '3'), usedefaults=None)
     self.assertSetEqual(e, set(('1', '2', '3')))
     self.assertTrue(e.match(Path('1')))
     self.assertFalse(e.match(Path('testhelper.pyc')))
     if self.vcsdir is not None:
         self.assertFalse(e.match(self.vcsdir))
Exemple #10
0
 def test_chmod(self):
     f = Path(self.tpath, 'chmod.f')
     self.assertFalse(f.exists)
     self.assertIsNone(f.chmod(0777))  # when file doesn't exist
     f.open()
     self.assertTrue(f.exists)
     self.assertIsNone(f.chmod(0777))
     self.assertEqual(f.mode, 0777)
Exemple #11
0
 def test_mtime(self):
     import time
     now = int(time.time())
     p = Path(self.tpath, 'mtime.f')
     self.assertIsNone(p.mtime)
     p.open('w')
     os.utime(str(p), (now, now))
     self.assertEqual(p.mtime, now)
Exemple #12
0
 def _test_call_uptodate(self):
     Path(self.dir, 'call_uptodate.older').open('w').close()
     Path(self.dir, 'call_uptodate.newer').open('w').close()
     utd = TestCallUptodate_utd()
     result = utd()
     self.assertTrue(result)
     target = TestCallUptodate_T()
     self.assertTrue(TestCallUptodate_utd()())
Exemple #13
0
 def test__init__(self):
     f = Path()
     self.assertFalse(f.has_variable)
     f = Path(V('basedir'))
     self.assertTrue(f.has_variable)
     f = Path('.', '/etc')
     self.assertEqual(f.components, ['', 'etc'])
     self.assertRaises(AttributeError, Path, [])
Exemple #14
0
 def test_chdir(self):
     cwd = Path.cwd()
     try:
         self.assertIsNone(self.tpath.chdir())
         self.assertEqual(os.getcwd(), self.tdir)
         self.assertRaises((IOError, OSError),
                           Path('chdir.n').chdir)  # dir that doesn't exist
     finally:
         cwd.chdir()
Exemple #15
0
 def test_cwd(self):
     scd = os.path.abspath(os.curdir)
     sd = os.getcwd()
     srd = os.path.abspath(sd)
     here = Path.cwd()
     self.assertIsInstance(here, Path)
     self.assertEqual(scd, srd)
     self.assertEqual(here.value, scd)
     self.assertEqual(Path('foo').cwd().value, scd)
Exemple #16
0
 def test__eq_(self):
     f1 = Path('etc')
     f2 = Path('etc')
     f3 = Path('etcetera')
     self.assertTrue(f1 == 'etc')
     self.assertTrue(f1 == f2)
     self.assertTrue('etc' == f1)
     self.assertFalse(f1 == f3)
     self.assertFalse(f1 == 'foobar')
     self.assertFalse('foobar' == f1)
Exemple #17
0
 def testexclude(self):
     obj = Iterator('foo.py', 'foo.py~', 'foo.pyc')
     self.assertEqual(tuple(obj), (Path('foo.py'), ))
     obj = Iterator('foo.py', 'foo.c', exclude='*.py')
     self.assertEqual(tuple(obj), (Path('foo.c'), ))
     obj = Iterator('foo.py',
                    'foo.py~',
                    'foo.pyc',
                    exclude=Exclusions(usedefaults=None))
     self.assertEqual(tuple(obj),
                      (Path('foo.py'), Path('foo.py~'), Path('foo.pyc')))
Exemple #18
0
 def test_copy(self):
     data = '=' * 256
     n = Path(self.tpath, 'copy.0')
     f = Path(self.tpath, 'copy.1')
     o = Path(self.tpath, 'copy.2')
     f.open().write(data)
     self.assertEqual(len(f), 256)
     f.copy(o)
     self.assertTrue(o.isfile)
     self.assertEqual(len(o), 256)
     self.assertEqual(o.open().read(), data)
     self.assertRaises(IOError, n.copy, o)
Exemple #19
0
 def test__len_(self):
     f = Path(self.tpath, 'len.f')
     d = Path(self.tpath, 'len.d')
     f.open('w').write('=' * 256)
     self.assertEqual(len(f), 256)
     d.mkdir()
     for i in range(2):
         Path(d, str(i)).open('w')
     self.assertEqual(len(d), 2)
Exemple #20
0
 def test_normalize(self):
     self.assertEqual(Path._normalize([]), [])
     self.assertEqual(Path._normalize(['']), ['', ''])
     self.assertEqual(Path._normalize([os.curdir]), [])
     self.assertEqual(Path._normalize(['', '']), ['', ''])
     self.assertEqual(Path._normalize([os.pardir]), [os.pardir])
     self.assertEqual(Path._normalize(['a', os.curdir, 'b']), ['a', 'b'])
     self.assertEqual(Path._normalize(['a', 'b', os.pardir]), ['a'])
     self.assertEqual(Path._normalize([V('basedir')]), [V('basedir')])
     self.assertEqual(Path._normalize(['', 'etc', os.pardir]), ['', ''])
     self.assertRaises(Exception, Path._normalize)
Exemple #21
0
 def test_open(self):
     f1 = Path(self.tpath, 'open.f')
     self.assertRaises(TypeError, f1.open, 'r')
     f = f1.open()
     self.assertIsInstance(f, file)
     self.assertTrue(f1.isfile)
     self.assertEqual(f.mode, 'w')
     f.close()
     f = f1.open()
     self.assertIsInstance(f, file)
     self.assertEqual(f.mode, 'r')
     f.close()
     os.remove(f1.value)
     os.mkdir(f1.value)
     self.assertRaises(TypeError, f1.open, 'w')
Exemple #22
0
 def test_variables(self):
     from ..variables import V
     v = V('path_variables_a', 'foo')
     p = Path('xyzzy', v, 'README')
     self.assertEqual(p.value, 'xyzzy/foo/README')
     v.value = 'bar'
     self.assertEqual(p.value, 'xyzzy/bar/README')
Exemple #23
0
 def test_readlink(self):
     n = Path(self.tpath, 'readlink.n')  # does not exist
     l = Path(self.tpath, 'readlink.l')  # existing link
     f = Path(self.tpath, 'readlink.f')  # existing file
     f.open()
     os.symlink(f.value, l.value)
     self.assertEqual(l.readlink(), f)
     self.assertRaises(TypeError, n.readlink)
     self.assertRaises(TypeError, f.readlink)
Exemple #24
0
 def test_end_to_end(self):
     p1 = Path(self.dir, 'e2e_t1')
     p2 = Path(self.dir, 'e2e_t2')
     self.assertFalse(p1.isfile)
     self.assertFalse(p2.isfile)
     target = TestE2E_T()
     self.assertIsNone(target())
     self.assertTrue(p1.isfile)
     self.assertTrue(p2.isfile)
     t1 = p1.mtime
     t2 = p2.mtime
     # maybe change the mtime of one then other to test uptodate?
     target = TestE2E_T()
     self.assertIsNone(target())
     # not testing what I think should be tested
     self.assertEqual(round(t1, 4), round(p1.mtime, 4))
     self.assertEqual(round(t2, 4), round(p2.mtime, 4))
Exemple #25
0
 def testprocess(self):
     h = Arguments()
     a = h.process((), {})
     self.assertIsInstance(a, ArgumentSet)
     self.assertItemsEqual(a.list, ())
     self.assertItemsEqual(a.map, {})
     with self.assertRaises(ValueError):
         h.process(('foo', ), {})  # not expecting positional arguments
         h.process((), {'foo': 'a'})  # not a valid keyword
     h = Arguments(
         Arguments.List('xyzzy'),
         Arguments.Keyword('foo', types=int, default=5),
         Arguments.Keyword('bar', types=tuple, default=()),
         Arguments.Keyword('ni'),
     )
     a = h.process((), {})
     self.assertItemsEqual(a.list, ())
     self.assertItemsEqual(a.map, {
         'ni': None,
         'foo': 5,
         'bar': (),
         'xyzzy': ()
     })
     a1 = h.process(('foo', ), {})
     self.assertNotEqual(a, a1)
     self.assertItemsEqual(a1.list, ('foo', ))
     self.assertItemsEqual(a1.map, {
         'ni': None,
         'foo': 5,
         'bar': (),
         'xyzzy': ('foo', )
     })
     del a1
     with self.assertRaises(TypeError):
         h.process((5, ), {})
         h.process((), {'ni': 5})
         h.process((), {'bar': 'far'})
     a = h.process(('a', '', 'c'), {'bar': ('8', 9, '10')})
     self.assertItemsEqual(a.list, ('a', '', 'c'))
     self.assertItemsEqual(a.map['bar'], ('8', 9, '10'))
     b = h.process(('d', 'e'), {'ni': 'arcege'}, existing=a)
     self.assertItemsEqual(b.list, ('d', 'e'))
     self.assertItemsEqual(b.map, {
         'ni': 'arcege',
         'bar': ('8', '9', '10'),
         'foo': 5,
         'xyzzy': ('d', 'e')
     })
     h = Arguments(
         Arguments.Keyword('foo', types=Path, default=Path('hi')),
         Arguments.Keyword('bar'),
     )
     a = h.process((), {})
     self.assertIsInstance(a.foo, Path)
     self.assertEqual(a.foo.value, 'hi')
     self.assertIsNone(a.bar)
     with self.assertRaises(ValueError):
         h.process((), {'xyzzy': 'hi'})
Exemple #26
0
 def testpattern(self):
     obj = Iterator('foo.py',
                    'foo.pyc',
                    'foo.c',
                    'bar.txt',
                    'testfoo.py',
                    pattern='*.py')
     # foo.pyc is excluded
     self.assertEqual(list(obj), [Path('foo.py'), Path('testfoo.py')])
     obj = Iterator('foo.py',
                    'foo.pyc',
                    'foo.c',
                    'bar.txt',
                    'testfoo.py',
                    pattern='*.py*')
     # foo.pyc is excluded
     self.assertEqual(list(obj), [Path('foo.py'), Path('testfoo.py')])
     obj = Iterator('foo.py',
                    'foo.pyc',
                    'foo.c',
                    'bar.txt',
                    'testfoo.py',
                    pattern='*foo*')
     self.assertEqual(
         list(obj),
         [Path('foo.py'), Path('foo.c'),
          Path('testfoo.py')])
Exemple #27
0
 def test_makepipe(self):
     mask = os.umask(0)
     try:
         n = Path(self.tpath, 'makepipe.n')  # does not exist
         f = Path(self.tpath, 'makepipe.f')  # existing file
         readonly = int('0666', 8)
         readwrite = int('0777', 8)
         f.open()
         self.assertRaises(TypeError, f.makepipe)
         self.assertIsNone(n.makepipe())
         self.assertEqual(n.type, Path.TYPE.PIPE)
         self.assertEqual(n.mode, readonly)
         n.remove()
         self.assertIsNone(n.makepipe(readwrite))
         self.assertEqual(n.type, Path.TYPE.PIPE)
         self.assertEqual(n.mode, readwrite)
     finally:
         os.umask(mask)
Exemple #28
0
 def test_mkdir(self):
     n = Path(self.tpath, 'mkdir.n')  # does not exist
     f = Path(self.tpath, 'mkdir.f')  # existing file
     d = Path(self.tpath, 'mkdir.d')  # existing directory
     d1 = d + 'subdir'
     d2 = d1 + 'subsubdir'
     f.open()
     os.mkdir(d.value)  # do it the old fashioned way for now
     self.assertTrue(f.isfile)
     self.assertRaises(TypeError, f.mkdir)
     self.assertIsNone(n.mkdir())
     self.assertTrue(n.isdir)
     self.assertTrue(d.isdir)
     self.assertIsNone(d.mkdir())
     self.assertFalse(d2.exists)
     self.assertIsNone(d2.mkdir())
     self.assertTrue(d2.isdir)
     self.assertTrue(d1.isdir)
Exemple #29
0
 def testcvs_info_svn(self):
     if self.havesvn:
         # string format used by SVN
         V['basedir'] = Path(self.svndir)
         VCS(rootdir=self.svndir)
         self.assertEqual(Variable('svn.version').value, '0')
         self.assertEqual(Variable('svn.branch').value, '')
         self.assertEqual(Variable('svn.tags').value, '')
         self.assertEqual(Variable('svn.user').value, '')
Exemple #30
0
 def testvcs_info_git(self):
     if self.havegit:
         V['basedir'] = Path(self.gitdir)
         VCS(rootdir=self.gitdir)
         self.assertEqual(Variable('git.version').value, '')
         self.assertEqual(Variable('git.branch').value, '')
         self.assertEqual(Variable('git.tags').value, '')
         self.assertEqual(Variable('git.user').value, '')
         self.assertEqual(Variable('git.date').value, '')