示例#1
0
 def test_onLinux(self):
     model = pm.PMakeupModel()
     model.input_string = """
     echo(on_windows())
     """
     self.assertStdoutEquals("False" if os.name == "posix" else "True",
                             lambda: model.manage_pmakefile())
示例#2
0
文件: test.py 项目: Koldar/pmakeup
    def test_archive_01_autoregister(self):
        model = pm.PMakeupModel()

        model.input_string = """
            make_directories("temp/foo/bar")
            make_directories("temp/foo2/bar")
            make_directories("temp/foo2/baz")
            create_empty_file("temp/foo/bar/empty.txt")
            create_empty_file("temp/foo2/bar/empty1.dat")
            create_empty_file("temp/foo2/bar/empty2.txt")
            zip_files(
                files=["temp/foo/bar/empty.txt", "temp/foo2/bar/empty1.dat", "temp/foo2/bar/empty2.txt"],
                base_dir="temp/",
                zip_name="text.zip",
                zip_format="zip",
                create_folder_in_zip_file=False,
            )

            echo(is_file_exists("text.zip"))
            echo(is_file_non_empty("text.zip"))

            remove_tree("temp")
            remove_file("text.zip")
        """
        self.assertStdoutEquals("True\nTrue", lambda: model.manage_pmakefile())
示例#3
0
文件: tests.py 项目: Koldar/pmakeup
    def test_has_git_config_ko(self):

        model = pm.PMakeupModel()
        model.input_string = """
            echo(has_git_config("user.edghdname"))
        """
        self.assertStdoutEquals(f"False", lambda: model.manage_pmakefile())
示例#4
0
 def test_echo_01(self):
     model = pm.PMakeupModel()
     model.input_string = """
     echo("Hello world!")
     """
     self.assertStdoutEquals("Hello world!",
                             lambda: model.manage_pmakefile())
示例#5
0
 def test_copy_folder_content(self):
     model = pm.PMakeupModel()
     model.cli_variables = {"foo": "bar"}
     model.input_string = """
         create_empty_directory("temp_copy")
         old_pwd = cwd()
         cd("temp_copy")
         create_empty_file("foo.txt")
         create_empty_file("bar.txt")
         create_empty_file("baz.txt")
         cd(old_pwd)
         create_empty_directory("temp2_copy")
         
         copy_folder_content(
             folder="temp_copy",
             destination="temp2_copy",
         )
         if is_file_exists(os.path.join("temp2_copy", "bar.txt")):
             echo("Hello")
         if not is_directory_exists(os.path.join("temp2_copy", "temp_copy")):
             echo("World")
     """
     self.assertStdoutEquals("Hello\nWorld",
                             lambda: model.manage_pmakefile())
     shutil.rmtree("temp_copy")
     shutil.rmtree("temp2_copy")
示例#6
0
 def test_commands(self):
     model = pm.PMakeupModel()
     model.input_string = """
         commands.echo("Hello world")
     """
     self.assertStdoutEquals("Hello world",
                             lambda: model.manage_pmakefile())
示例#7
0
 def test_variables_03(self):
     model = pm.PMakeupModel()
     model.cli_variables = {"foo": "bar"}
     model.input_string = """
         echo(vars().foo)
     """
     self.assertStdoutEquals("bar", lambda: model.manage_pmakefile())
示例#8
0
 def test_echo_02(self):
     model = pm.PMakeupModel()
     model.input_string = """
     x = 3
     echo(f"Hello {x}!")
     """
     self.assertStdoutEquals("Hello 3!", lambda: model.manage_pmakefile())
示例#9
0
 def test_whoami(self):
     model = pm.PMakeupModel()
     model.input_string = """
         echo(current_user())
     """
     self.assertStdout(lambda stdout: len(stdout) > 0,
                       lambda: model.manage_pmakefile())
示例#10
0
 def test_admin_fire_and_forget_windows(self):
     if os.name == "nt":
         model = pm.PMakeupModel()
         model.input_string = """
             echo(execute_admin_and_forget("echo hello > temp.txt"))
         """
         self.assertStdoutEquals("0", lambda: model.manage_pmakefile())
示例#11
0
 def test_execute_admin_with_password_return_stdout(self):
     if os.name == "posix":
         model = pm.PMakeupModel()
         model.input_string = """
             password = read_file_content("../PASSWORD")
             echo(execute_admin_with_password_return_stdout(["echo hello"], password)[1])
         """
         self.assertStdoutEquals("hello", lambda: model.manage_pmakefile())
示例#12
0
 def test_include(self):
     model = pm.PMakeupModel()
     model.input_string = """
         write_file("test-temp.py", "echo(\\"Hello\\")")
         include_file("test-temp.py")
         remove_file("test-temp.py")
     """
     self.assertStdoutEquals("Hello", lambda: model.manage_pmakefile())
示例#13
0
 def test_admin_execute_return_stdout_windows(self):
     if os.name == "nt":
         model = pm.PMakeupModel()
         model.input_string = """
             exit_code, v, _ = execute_admin_return_stdout("echo hello")
             echo(v)
         """
         self.assertStdoutEquals("hello", lambda: model.manage_pmakefile())
示例#14
0
 def test_download_url(self):
     model = pm.PMakeupModel()
     model.input_string = """
         download_url("https://www.google.com", "Hello.html")
         echo(is_file_non_empty("Hello.html"))
     """
     self.assertStdoutEquals("True", lambda: model.manage_pmakefile())
     os.unlink("Hello.html")
示例#15
0
 def test_read_lines(self):
     model = pm.PMakeupModel()
     model.input_string = """
         write_lines(f"Hello", ["5", "6", "7"])
         echo(', '.join(read_lines("Hello")))
         """
     self.assertStdoutEquals("5, 6, 7", lambda: model.manage_pmakefile())
     os.unlink("Hello")
示例#16
0
 def test_has_processes(self):
     if os.name == "nt":
         model = pm.PMakeupModel()
         model.input_string = """
             echo(is_process_running("winlogon.exe"))
             echo(is_process_running("asdrubalini.exe"))
         """
         self.assertStdoutEquals("True\nFalse",
                                 lambda: model.manage_pmakefile())
     elif os.name == "posix":
         model = pm.PMakeupModel()
         model.input_string = """
             echo(is_process_running("winlogon.exe"))
             echo(is_process_running("asdrubalini.exe"))
         """
         self.assertStdoutEquals("True\nFalse",
                                 lambda: model.manage_pmakefile())
示例#17
0
 def test_is_file_empty(self):
     model = pm.PMakeupModel()
     model.input_string = """
         create_empty_file(f"Hello")
         echo(is_file_empty("Hello"))
         """
     self.assertStdoutEquals("True", lambda: model.manage_pmakefile())
     os.unlink("Hello")
示例#18
0
 def test_get_program_path(self):
     if os.name == "nt":
         model = pm.PMakeupModel()
         model.input_string = """
             echo("C:\\Windows" in get_program_path())
             echo(len(get_program_path()) > 5)
         """
         self.assertStdoutEquals("True\nTrue",
                                 lambda: model.manage_pmakefile())
     elif os.name == "posix":
         model = pm.PMakeupModel()
         model.input_string = """
                         echo("/usr/local/bin" in get_program_path())
                         echo(len(get_program_path()) > 5)
                     """
         self.assertStdoutEquals("True\nTrue",
                                 lambda: model.manage_pmakefile())
示例#19
0
 def test_write_file(self):
     model = pm.PMakeupModel()
     model.input_string = """
         write_file(f"Hello", "5")
         echo(read_file_content("Hello"))
         """
     self.assertStdoutEquals("5", lambda: model.manage_pmakefile())
     os.unlink("Hello")
示例#20
0
 def test_create_empty_file(self):
     model = pm.PMakeupModel()
     model.input_string = """
     create_empty_file(f"Hello")
     """
     model.manage_pmakefile()
     self.assertTrue(os.path.exists("Hello"))
     os.unlink("Hello")
示例#21
0
 def test_default_internet_explorer(self):
     if os.name == 'nt':
         model = pm.PMakeupModel()
         model.input_string = """
             echo(get_latest_path_with_architecture("internet-explorer", 64))
         """
         self.assertStdoutEquals(
             os.path.join("C:\\", "Program Files", "Internet Explorer",
                          "iexplore.exe"), lambda: model.manage_pmakefile())
示例#22
0
 def test_read_registry_keys(self):
     if os.name == 'nt':
         model = pm.PMakeupModel()
         model.input_string = """
                     echo(len(list(get_registry_local_machine_values(
                         key=r"SOFTWARE\\Microsoft\\Clipboard",
                     ))))
                 """
         self.assertStdoutEquals("2", lambda: model.manage_pmakefile())
示例#23
0
 def test_execute_stdout_on_screen_windows(self):
     if os.name == "nt":
         model = pm.PMakeupModel()
         model.input_string = """
             execute_stdout_on_screen("echo hello > temp.txt")
             echo(read_file_content("temp.txt"))
             remove_file("temp.txt")
         """
         self.assertStdoutEquals("hello", lambda: model.manage_pmakefile())
示例#24
0
 def test_is_program_installed_windows(self):
     if os.name == "nt":
         model = pm.PMakeupModel()
         model.input_string = """
             echo(is_program_installed("cmd.exe"))
             echo(is_program_installed("opasdfhiovsefuhawzxcvsdvbjkfawfhsd"))
         """
         self.assertStdoutEquals("True\nFalse",
                                 lambda: model.manage_pmakefile())
示例#25
0
 def test_execute_stdout_on_screen(self):
     if os.name == "posix":
         model = pm.PMakeupModel()
         model.input_string = """
             execute_stdout_on_screen(["echo hello > temp.txt"], cwd=cwd())
             echo(read_file_content("/tmp/temp.txt"))
             remove_file("/tmp/temp.txt")
         """
         self.assertStdoutEquals("hello", lambda: model.manage_pmakefile())
示例#26
0
 def test_default_has_registry_local_machine_value(self):
     if os.name == 'nt':
         model = pm.PMakeupModel()
         model.input_string = """
             echo(has_registry_local_machine_value(
                 key=r"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE",
                 item=""
             ))
         """
         self.assertStdoutEquals("True", lambda: model.manage_pmakefile())
示例#27
0
 def test_has_registry_value_absent(self):
     if os.name == 'nt':
         model = pm.PMakeupModel()
         model.input_string = """
                     echo(has_registry_local_machine_value(
                         key=r"SOFTWARE\\Microsoft\\FilePicker",
                         item="Seedsdjkf"
                     ))
                 """
         self.assertStdoutEquals("False", lambda: model.manage_pmakefile())
示例#28
0
 def test_read_registry_key(self):
     if os.name == 'nt':
         model = pm.PMakeupModel()
         model.input_string = """
                     echo(read_registry_local_machine_value(
                         key=r"SOFTWARE\\Microsoft\\Clipboard",
                         item="IsClipboardSignalProducingFeatureAvailable"
                     ))
                 """
         self.assertStdoutEquals("1", lambda: model.manage_pmakefile())
示例#29
0
 def test_find_executable_in_program_directories(self):
     if os.name == "nt":
         model = pm.PMakeupModel()
         model.input_string = """
             echo(find_executable_in_program_directories("hsdghsdklghdf"))
             echo(find_executable_in_program_directories("iexplore.exe"))
         """
         self.assertStdoutEquals(
             "None\nC:\\Program Files\\Internet Explorer\\iexplore.exe",
             lambda: model.manage_pmakefile())
示例#30
0
 def test_get_absolute_file_till_root_01(self):
     model = pm.PMakeupModel()
     model.input_string = """
                 make_directories("temp1/temp2/temp3/temp4")
                 create_empty_file("temp1/awesome")
                 result = get_absolute_file_till_root("awesome", "temp1/temp2/temp3/temp4") 
                 echo("awesome" in result)
                 remove_tree("temp1")
             """
     self.assertStdoutEquals("True", lambda: model.manage_pmakefile())