Ejemplo n.º 1
0
 def test_existent(self):
     with mock.patch('bfg9000.path.exists', return_value=True), \
          mock.patch('bfg9000.path.isdir', return_value=True):
         self.assertPathEqual(parser.Directory()('foo'),
                              path.abspath('foo/', absdrive=False))
         self.assertPathEqual(parser.Directory(True)('foo'),
                              path.abspath('foo/', absdrive=False))
Ejemplo n.º 2
0
 def test_not_dir(self):
     with mock.patch('bfg9000.path.exists', return_value=True), \
          mock.patch('bfg9000.path.isdir', return_value=False):  # noqa
         with self.assertRaises(parser.ArgumentTypeError):
             parser.Directory()('foo')
         with self.assertRaises(parser.ArgumentTypeError):
             parser.Directory(True)('foo')
Ejemplo n.º 3
0
    def test_complete(self):
        p = parser.ArgumentParser()
        arg = p.add_argument('--arg', complete='file')
        self.assertEqual(arg.complete, 'file')

        file_arg = p.add_argument('--file', type=parser.File())
        self.assertEqual(file_arg.complete, 'file')

        dir_arg = p.add_argument('--dir', type=parser.Directory())
        self.assertEqual(dir_arg.complete, 'directory')
Ejemplo n.º 4
0
 def test_existent(self):
     with mock.patch('bfg9000.path.exists', return_value=True), \
          mock.patch('bfg9000.path.isdir', return_value=True):  # noqa
         self.assertEqual(parser.Directory()('foo'), path.abspath('foo'))
         self.assertEqual(
             parser.Directory(True)('foo'), path.abspath('foo'))
Ejemplo n.º 5
0
 def test_nonexistent(self):
     with mock.patch('bfg9000.path.exists', return_value=False):
         self.assertEqual(parser.Directory()('foo'), path.abspath('foo'))
         with self.assertRaises(parser.ArgumentTypeError):
             parser.Directory(True)('foo')