Esempio n. 1
0
 def test_existent(self):
     with mock.patch('bfg9000.path.exists', return_value=True), \
          mock.patch('bfg9000.path.isfile', return_value=True):  # noqa
         self.assertPathEqual(parser.File()('foo'),
                              path.abspath('foo', absdrive=False))
         self.assertPathEqual(
             parser.File(True)('foo'), path.abspath('foo', absdrive=False))
Esempio n. 2
0
 def test_not_dir(self):
     with mock.patch('bfg9000.path.exists', return_value=True), \
          mock.patch('bfg9000.path.isfile', return_value=False):  # noqa
         with self.assertRaises(parser.ArgumentTypeError):
             parser.File()('foo')
         with self.assertRaises(parser.ArgumentTypeError):
             parser.File(True)('foo')
Esempio 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')
Esempio n. 4
0
 def test_nonexistent(self):
     with mock.patch('bfg9000.path.exists', return_value=False):
         self.assertEqual(parser.File()('foo'), path.abspath('foo'))
         with self.assertRaises(parser.ArgumentTypeError):
             parser.File(True)('foo')