Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-van committed Apr 25, 2023
1 parent 508ce6a commit 01113d9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
15 changes: 12 additions & 3 deletions test_ressources/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def run_echoer_with_cmd_through_python_subprocess(str):
finally:
shutil.rmtree(tmp_folder)

def run_echoer_with_powershell_through_script(str):

def __run_echoer_with_powershell_through_script_common(str, executable):
tmp_folder = tempfile.mkdtemp()
try:
# create the bat file
Expand All @@ -61,12 +62,20 @@ def run_echoer_with_powershell_through_script(str):
f.write(cmd_file_content)

# perform the call
subprocess.check_call(["powershell", cmd_file_name], stdout=subprocess.DEVNULL)
subprocess.check_call([executable, cmd_file_name], stdout=subprocess.DEVNULL)

# get the results
with open(output_file_path, 'r', encoding="utf-8", newline='') as f:
output_content = f.read()

return output_content
finally:
shutil.rmtree(tmp_folder)
shutil.rmtree(tmp_folder)


def run_echoer_with_powershell_through_script(str):
return __run_echoer_with_powershell_through_script_common(str, 'powershell')


def run_echoer_with_pwsh_through_script(str):
return __run_echoer_with_powershell_through_script_common(str, 'powershell')
39 changes: 26 additions & 13 deletions test_win_cmd_escaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ def test_basic_calls(self):
self._test_str("hello")
self._test_str("hello world")

def test_empty(self):
self._test_str("")

def test_printable_ascii_only_char(self):
for i in range(32, 127):
character = chr(i)
Expand Down Expand Up @@ -105,36 +102,52 @@ def test_double_quotes(self):
self._test_str('"\\\\')
self._test_str('"\\\\\\')

def test_latin_1(self):
self._test_str('Aéèàù')
class AllCmdTests(AllTests):

def test_emoji(self):
self._test_str('😊❤️😍😁👍')
def test_empty(self):
self._test_str("")

class CmdScriptTests(unittest.TestCase, AllTests):

class CmdScriptTests(unittest.TestCase, AllCmdTests):

def escape(self, str):
return win_cmd_escaper.escape_cmd_argument_script(str)

def run_echoer(self, str):
return test_utils.run_echoer_with_cmd_through_script(str)


class CmdPythonSubprocessTests(unittest.TestCase, AllTests):
class CmdPythonSubprocessTests(unittest.TestCase, AllCmdTests):

def escape(self, str):
return win_cmd_escaper.escape_cmd_argument_direct(str)

def run_echoer(self, str):
return test_utils.run_echoer_with_cmd_through_python_subprocess(str)



class PowershellScriptTests(unittest.TestCase, AllTests):
class AllPowershellScriptTests(AllTests):

def escape(self, str):
return win_cmd_escaper.escape_powershell_argument_script(str)

def test_empty(self):
self._test_unsupported("")

def test_latin_1(self):
self._test_str('Aéèàù')

def test_emoji(self):
self._test_str('😊❤️😍😁👍')


class PowershellScriptTests(unittest.TestCase, AllPowershellScriptTests):

def run_echoer(self, str):
return test_utils.run_echoer_with_powershell_through_script(str)

def test_empty(self):
self._test_unsupported("")

class PwshScriptTests(unittest.TestCase, AllPowershellScriptTests):

def run_echoer(self, str):
return test_utils.run_echoer_with_pwsh_through_script(str)

0 comments on commit 01113d9

Please sign in to comment.