def main_entry_point(args: Optional[List[str]] = None): parsed = ParsedArgs(args) dirs = Dirs(project_dir=get_project_dir(parsed)) if parsed.command == Commands.create: main_create(dirs, parsed.python_executable) elif parsed.command == Commands.recreate: main_recreate(dirs, parsed.python_executable) # todo .existing()? elif parsed.command == Commands.delete: # todo move 'existing' check from func? main_delete(dirs.venv_dir) elif parsed.command == Commands.path: print(dirs.venv_dir) # does not need to be existing elif parsed.command == Commands.run: # todo allow running commands from strings main_run(dirs.venv_must_exist(), parsed.run_args) elif parsed.command == Commands.call: main_call(parsed, dirs) elif parsed.command == Commands.shell: main_shell(dirs, parsed.shell_input, parsed.shell_delay) else: raise ValueError
def test_call_field(self): pd = ParsedArgs('-p a/b/c call -m myfile.py arg1 arg2'.split()) self.assertIsNotNone(pd.call) self.assertEqual(pd.call.filename, "myfile.py") self.assertEqual(pd.call.before_filename, "-m")
def test_unrecoginzed(self): """Unrecognized arguments that are NOT after the 'call' word.""" with self.assertRaises(SystemExit) as ce: ParsedArgs('-labuda call myfile.py a b c'.split()) self.assertEqual(ce.exception.code, 2)
def test_p(self): pd = ParsedArgs('-p a/b/c call -d myfile.py a b c'.split()) self.assertEqual(pd.args_to_python, ['-d', 'myfile.py', 'a', 'b', 'c'])
def test_outdated_p(self): pd = ParsedArgs('-p a/b/c call -p d/e/f myfile.py arg1 arg2'.split()) self.assertEqual(pd.args_to_python, ['myfile.py', 'arg1', 'arg2'])
def test_call_short_both(self): pd = ParsedArgs('-p a/b/c call -p d/e/f myfile.py'.split()) self.assertEqual(pd.project_dir_arg, 'd/e/f')
def test_call_long_left(self): pd = ParsedArgs('--project-dir a/b/c call myfile.py'.split()) self.assertEqual(pd.project_dir_arg, 'a/b/c')
def test_input(self): pd = ParsedArgs(windows_too(['shell', '--input', 'cd / && ls'])) self.assertEqual(pd.shell_input, 'cd / && ls')
def test_run_long_left(self): pd = ParsedArgs( windows_too('--project-dir a/b/c run python3 myfile.py'.split())) self.assertEqual(pd.project_dir_arg, 'a/b/c')
def test_windowsallargs_fails_on_posix(self): # is the PARAM_WINDOWS_ALL_ARGS is set, we must run windows. # Otherwise, AssertionError is thrown with self.assertRaises(AssertionError): ParsedArgs([ParsedArgs.PARAM_WINDOWS_ALL_ARGS, 'shell'])
def test_without_arg(self): pd = ParsedArgs(['recreate']) self.assertEqual(pd.command, Commands.recreate) self.assertEqual(pd.python_executable, None)
def test_with_arg(self): pd = ParsedArgs(['create', 'python3']) self.assertEqual(pd.command, Commands.create) self.assertEqual(pd.python_executable, "python3")
def test(self): pd = ParsedArgs(windows_too(['run', 'python3', '-OO', 'file.py'])) self.assertEqual(pd.command, Commands.run) self.assertEqual(pd.run_args, ['python3', '-OO', 'file.py'])
def test_labuda(self): with self.assertRaises(SystemExit) as ce: pd = ParsedArgs(windows_too('shell --labuda'.split())) self.assertEqual(ce.exception.code, 2)
def test_delay(self): pd = ParsedArgs(windows_too('shell --delay 1.2'.split())) self.assertEqual(pd.shell_delay, 1.2)
def _gpd(self, cmd: str) -> Path: cmd = fix_paths(cmd) result = get_project_dir(ParsedArgs(windows_too(cmd.split()))) self.assertTrue(result.is_absolute()) return result
def test_call_short_right(self): pd = ParsedArgs('call -p a/b/c myfile.py'.split()) self.assertEqual(pd.project_dir_arg, 'a/b/c')
def test_no_args(self): pd = ParsedArgs(windows_too('shell'.split())) self.assertEqual(pd.command, Commands.shell) self.assertEqual(pd.shell_delay, None) self.assertEqual(pd.shell_input, None)