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