<commit_before>import os
import sys
import unittest

sys.path.insert(0, ".")
from coalib.misc.Shell import (prepare_string_argument,
                               escape_path_argument,
                               run_interactive_shell_command,
                               run_shell_command)


class ShellTest(unittest.TestCase):
    # Tests the function that makes a path shell-argument-ready.

    def test_escape_path_argument(self):
        osnames = ("Linux", "Darwin")

        for osname in osnames:
            self.assertEqual(
                escape_path_argument("/home/usr/a-file", osname),
                "/home/usr/a-file")
            self.assertEqual(
                escape_path_argument("/home/usr/a-dir/", osname),
                "/home/usr/a-dir/")
            self.assertEqual(
                escape_path_argument("/home/us r/a-file with spaces.bla",
                                     osname),
                "/home/us\\ r/a-file\\ with\\ spaces.bla")
            self.assertEqual(
                escape_path_argument("/home/us r/a-dir with spaces/x/",
                                     osname),
                "/home/us\\ r/a-dir\\ with\\ spaces/x/")
            self.assertEqual(
                escape_path_argument(
                    "relative something/with cherries and/pickles.delicious",
                    osname),
                "relative\\ something/with\\ cherries\\ and/pickles.delicious")

        osname = "Windows"
        self.assertEqual(
            escape_path_argument("C:\\Windows\\has-a-weird-shell.txt", osname),
            "\"C:\\Windows\\has-a-weird-shell.txt\"")
        self.assertEqual(
            escape_path_argument("C:\\Windows\\lolrofl\\dirs\\", osname),
            "\"C:\\Windows\\lolrofl\\dirs\\\"")
        self.assertEqual(
            escape_path_argument("X:\\Users\\Maito Gai\\fi le.exe", osname),
            "\"X:\\Users\\Maito Gai\\fi le.exe\"")
        self.assertEqual(
            escape_path_argument("X:\\Users\\Mai to Gai\\director y\\",
                                 osname),
            "\"X:\\Users\\Mai to Gai\\director y\\\"")
        self.assertEqual(
            escape_path_argument("X:\\Users\\<NAME>ai\\\"seven-gates\".y",
                                 osname),
            "\"X:\\Users\\<NAME>\\^\"seven-gates^\".y\"")
        self.assertEqual(
            escape_path_argument("System32\\my-custom relative tool\\",
                                 osname),
            "\"System32\\my-custom relative tool\\\"")
        self.assertEqual(
            escape_path_argument("System32\\illegal\" name \"\".curd", osname),
            "\"System32\\illegal^\" name ^\"^\".curd\"")
<commit_msg>ShellTest: Split cases for escape_path_argument<commit_after>import os
import sys
import unittest

sys.path.insert(0, ".")
from coalib.misc.Shell import (prepare_string_argument,
                               escape_path_argument,
                               run_interactive_shell_command,
                               run_shell_command)


class EscapePathArgumentTest(unittest.TestCase):

    def test_escape_path_argument_linux_and_darwin(self):
        osnames = ("Linux", "Darwin")

        for osname in osnames:
            self.assertEqual(
                escape_path_argument("/home/usr/a-file", osname),
                "/home/usr/a-file")
            self.assertEqual(
                escape_path_argument("/home/usr/a-dir/", osname),
                "/home/usr/a-dir/")
            self.assertEqual(
                escape_path_argument("/home/us r/a-file with spaces.bla",
                                     osname),
                "/home/us\\ r/a-file\\ with\\ spaces.bla")
            self.assertEqual(
                escape_path_argument("/home/us r/a-dir with spaces/x/",
                                     osname),
                "/home/us\\ r/a-dir\\ with\\ spaces/x/")
            self.assertEqual(
                escape_path_argument(
                    "relative something/with cherries and/pickles.delicious",
                    osname),
                "relative\\ something/with\\ cherries\\ and/pickles.delicious")

    def test_escape_path_argument_windows(self):
        osname = "Windows"
        self.assertEqual(
            escape_path_argument("C:\\Windows\\has-a-weird-shell.txt", osname),
            "\"C:\\Windows\\has-a-weird-shell.txt\"")
        self.assertEqual(
            escape_path_argument("C:\\Windows\\lolrofl\\dirs\\", osname),
            "\"C:\\Windows\\lolrofl\\dirs\\\"")
        self.assertEqual(
            escape_path_argument("X:\\Users\\Maito Gai\\fi le.exe", osname),
            "\"X:\\Users\\Maito Gai\\fi le.exe\"")
        self.assertEqual(
            escape_path_argument("X:\\Users\\Mai to Gai\\director y\\",
                                 osname),
            "\"X:\\Users\\Mai to Gai\\director y\\\"")
        self.assertEqual(
            escape_path_argument("X:\\Users\\Maito Gai\\\"seven-gates\".y",
                                 osname),
            "\"X:\\Users\\Maito Gai\\^\"seven-gates^\".y\"")
        self.assertEqual(
            escape_path_argument("System32\\my-custom relative tool\\",
                                 osname),
            "\"System32\\my-custom relative tool\\\"")
        self.assertEqual(
            escape_path_argument("System32\\illegal\" name \"\".curd", osname),
            "\"System32\\illegal^\" name ^\"^\".curd\"")

    def test_escape_path_argument_unsupported_os(self):
{'fraction_non_alphanumeric': 0.14423076923076922, 'fraction_numerical': 0.003265602322206096, 'mean_word_length': 1.4688759516345724, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6862560', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1543, 'n_words': 242}