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))
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')
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')
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')