예제 #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))
예제 #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')
예제 #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')
예제 #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'))
예제 #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')