def test_default_value_validation(self): with self.assertRaises(ValueError): questions.Path("path", default="~/.toggl_log", path_type=questions.Path.DIRECTORY) questions.Path("path", default="~/.toggl_log")
def test_normalizing_value(self): # Expanding Home home = os.environ.get('HOME') q = questions.Path('home') path = '~/some_path/some_file' self.assertNotIn(home, path) self.assertIn(home, q.normalize_value(path)) # Normalizing to absolute path q = questions.Path('abs_path', normalize_to_absolute_path=True) self.assertEqual('/', q.normalize_value('some/relative/path')[0])
def test_normalizing_value(self): # Expanding Home home = os.path.expanduser("~") q = questions.Path("home") path = "~/some_path/some_file" self.assertNotIn(home, path) self.assertIn(home, q.normalize_value(path)) # Normalizing to absolute path root = os.path.abspath(__file__).split(os.path.sep)[0] q = questions.Path("abs_path", normalize_to_absolute_path=True) self.assertEqual(root, q.normalize_value("some/relative/path").split(os.path.sep)[0])
def test_normalizing_value(self): # Expanding Home home = os.path.expanduser('~') q = questions.Path('home') path = '~/some_path/some_file' self.assertNotIn(home, path) self.assertIn(home, q.normalize_value(path)) # Normalizing to absolute path root = os.path.abspath(__file__).split(os.path.sep)[0] q = questions.Path('abs_path', normalize_to_absolute_path=True) self.assertEqual( root, q.normalize_value('some/relative/path').split(os.path.sep)[0])
def do_test(path_type, path, result=True): q = questions.Path("path_type_test", path_type=path_type) if result: self.assertIsNone(q.validate(path)) else: with self.assertRaises(errors.ValidationError): q.validate(path)
def do_test(path, result=True): q = questions.Path('validation_test') if result: self.assertIsNone(q.validate(path)) else: with self.assertRaises(errors.ValidationError): q.validate(path)
def path(message, render=None, **kwargs): render = render or ConsoleRender() question = questions.Path(name="", message=message, **kwargs) return render.render(question)