示例#1
0
    def test_init_command_venv_twice(self):
        command_init.entry_point(args=[])
        exit_code: int = command_init.entry_point(args=[])
        self.assertEqual(0, exit_code)
        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertTrue(os.path.isdir(os.path.abspath(_CURRENT_DIR+"/venv")))
        self.assertTrue(os.path.isfile(os.path.abspath(_CURRENT_DIR+"/caos.yml")))
        
        self.assertIn(_CREATING_VIRTUAL_ENVIRONMENT_MESSAGE, messages)
        messages: str = messages.replace(_CREATING_VIRTUAL_ENVIRONMENT_MESSAGE, "", 1)
        
        self.assertIn(_VIRTUAL_ENVIRONMENT_CREATED_MESSAGE, messages)
        messages: str = messages.replace(_VIRTUAL_ENVIRONMENT_CREATED_MESSAGE, "", 1)
        
        self.assertIn(_CREATING_YAML_MESSAGE, messages)
        messages: str = messages.replace(_CREATING_YAML_MESSAGE, "", 1)
        
        self.assertIn(_YAML_CREATED_MESSAGE, messages)
        messages: str = messages.replace(_YAML_CREATED_MESSAGE, "", 1)
        
        self.assertIn(_VIRTUAL_ENVIRONMENT_EXISTS_MESSAGE, messages)
        messages: str = messages.replace(_VIRTUAL_ENVIRONMENT_EXISTS_MESSAGE, "", 1)
        
        self.assertIn(_YAML_EXISTS_MESSAGE, messages)
示例#2
0
    def test_run_command_recursion(self):
        yaml_template = """\
        tasks:           
          1:
            - echo 1
          2:
            - 1
            - echo 2
          3:
            - 2
            - echo 3
        """

        yaml_path: str = os.path.abspath(_CURRENT_DIR + "/" +
                                         CAOS_YAML_FILE_NAME)
        self.assertFalse(os.path.isfile(yaml_path))
        with open(file=yaml_path, mode="w") as yaml_file:
            yaml_file.write(yaml_template)

        self.assertTrue(os.path.isfile(yaml_path))

        exit_code: int = command_run.entry_point(args=["3"])
        self.assertEqual(0, exit_code)

        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertIn("1\n2\n3", messages)
示例#3
0
    def test_pip_command_list(self):
        exit_code: int = command_init.entry_point(args=[])
        self.assertEqual(0, exit_code)
        self._restore_stdout()
        self._redirect_stdout()

        exit_code: int = command_pip.entry_point(args=["list"])
        self.assertEqual(0, exit_code)
        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertIn("pip", messages)
        self.assertIn("setuptools", messages)
示例#4
0
    def test_python_command_hello_world(self):
        exit_code: int = command_init.entry_point(args=[])
        self.assertEqual(0, exit_code)
        self._restore_stdout()
        self._redirect_stdout()

        exit_code: int = command_python.entry_point(
            args=["-c", "print('Hello World')"])
        self.assertEqual(0, exit_code)
        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertIn("Hello World", messages)
示例#5
0
    def test_init_command_simple(self):
        exit_code: int = command_init.entry_point(args=["--simple"])
        self.assertEqual(0, exit_code)
        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertFalse(os.path.isdir(os.path.abspath(_CURRENT_DIR+"/venv")))
        self.assertTrue(os.path.isfile(os.path.abspath(_CURRENT_DIR+"/caos.yml")))

        self.assertIn(_CREATING_YAML_MESSAGE, messages)
        messages: str = messages.replace(_CREATING_YAML_MESSAGE, "", 1)

        self.assertIn(_YAML_CREATED_MESSAGE, messages)
示例#6
0
    def test_update_command(self):
        exit_code: int = command_init.entry_point(args=[])
        self.assertEqual(0, exit_code)

        if is_win_os():
            self.assertTrue(os.path.isfile(PYTHON_PATH_VENV_WIN))
            self.assertTrue(os.path.isfile(PIP_PATH_VENV_WIN))
            python_path = PYTHON_PATH_VENV_WIN

        elif is_posix_os():
            self.assertTrue(os.path.isfile(PYTHON_PATH_VENV_POSIX))
            self.assertTrue(os.path.isfile(PIP_PATH_VENV_POSIX))
            python_path = PYTHON_PATH_VENV_POSIX

        self.assertTrue(
            os.path.isfile(os.path.abspath(_CURRENT_DIR + "/caos.yml")))
        with open(os.path.abspath(_CURRENT_DIR + "/caos.yml"), "w") as file:
            file.write("""
            virtual_environment: "venv"
            dependencies:
                pip: "latest"
                requests: "2.0.0"  
                numpy: "^1.18.2"
                flask: "~1.1.0"            
            """)

        exit_code: int = command_update.entry_point(args=[])
        self.assertEqual(0, exit_code)
        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertIn("INFO: Updating PIP...", messages)
        self.assertIn("SUCCESS: PIP was successfully updated", messages)
        self.assertIn("INFO: Installing dependencies...", messages)
        self.assertIn("SUCCESS: All dependencies have been installed",
                      messages)

        pip_list_process: subprocess.CompletedProcess = subprocess.run(
            [python_path, "-m", "pip", "list"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            universal_newlines=True)

        if pip_list_process.returncode != 0:
            self.fail("pip list failed")

        output: str = pip_list_process.stdout.lower()
        self.assertIn("pip", output)
        self.assertIn("requests", output)
        self.assertIn("numpy", output)
        self.assertIn("flask", output)
示例#7
0
    def test_help_command_alias(self):
        sys.argv = ["file_name", "-h"]
        cli_entry_point()
        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertIn(_DESCRIPTION_MESSAGE, messages)
        self.assertIn(_DESCRIPTION_CONTENT_MESSAGE, messages)

        self.assertIn(_PROGRAM_INFO_MESSAGE, messages)
        self.assertIn(_HELP_COMMAND_ARGUMENTS_MESSAGE, messages)
        self.assertIn(_HELP_COMMAND_DESCRIPTION_MESSAGE, messages)
        self.assertIn(_VERSION_COMMAND_ARGUMENTS_MESSAGE, messages)
        self.assertIn(_VERSION_COMMAND_DESCRIPTION_MESSAGE, messages)

        self.assertIn(_ARGUMENTS_MESSAGE, messages)
示例#8
0
 def test_help_command_init_output(self):
     sys.argv = ["file_name", "-h"]
     cli_entry_point()
     messages: str = escape_ansi(self.new_stdout.getvalue())
     self.assertIn(
         "Creates a Python virtual environment based on the configuration",
         messages)
     self.assertIn(
         "of an existing 'caos.yml' file in the current directory.",
         messages)
     self.assertIn(
         "If the 'caos.yml' file is not present in the current directory a",
         messages)
     self.assertIn(
         "new virtual environment and configuration file are created.",
         messages)
     self.assertIn("caos init", messages)
     self.assertIn("caos init [VIRTUAL_ENV_NAME]", messages)
示例#9
0
    def test_run_command_arguments_warning(self):
        yaml_template = """\
        tasks:           
          hello:
            - echo Hello World
        """

        yaml_path: str = os.path.abspath(_CURRENT_DIR + "/" +
                                         CAOS_YAML_FILE_NAME)
        self.assertFalse(os.path.isfile(yaml_path))
        with open(file=yaml_path, mode="w") as yaml_file:
            yaml_file.write(yaml_template)

        self.assertTrue(os.path.isfile(yaml_path))

        exit_code: int = command_run.entry_point(args=["hello", "arg"])
        self.assertEqual(0, exit_code)

        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertIn("WARNING: The tasks can't receive arguments", messages)
示例#10
0
    def test_check_command(self):
        exit_code: int = command_init.entry_point(args=[])
        self.assertEqual(0, exit_code)

        self.assertTrue(os.path.isfile(os.path.abspath(_CURRENT_DIR + "/caos.yml")))
        with open(os.path.abspath(_CURRENT_DIR + "/caos.yml"), "w") as file:
            file.write("""
            virtual_environment: "venv"
            dependencies:
                pip: "latest"
                requests: "2.0.0"     
            """)

        exit_code: int = command_update.entry_point(args=[])
        self.assertEqual(0, exit_code)

        exit_code: int = command_check.entry_point(args=[])
        self.assertEqual(0, exit_code)
        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertIn("SUCCESS: All dependencies are installed in the virtual environment", messages)
示例#11
0
    def test_invalid_command_argument_missing(self):
        sys.argv = ["file_name"]
        cli_entry_point()
        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertIn(_NO_ARG_MESSAGE, messages)
示例#12
0
    def test_invalid_command_argument_unknown(self):
        sys.argv = ["file_name", "some_weird_invalid_argument"]
        cli_entry_point()
        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertIn(_UNKNOWN_ARG, messages)
示例#13
0
    def test_version_command_alias2(self):
        sys.argv = ["file_name", "-V"]
        cli_entry_point()
        messages: str = escape_ansi(self.new_stdout.getvalue())

        self.assertIn(_VERSION_MESSAGE, messages)