Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_tokenizeCommandStr(self):
self.assertEqual(pyautogui._tokenizeCommandStr(""), []) # Empty command string.
self.assertEqual(pyautogui._tokenizeCommandStr(" "), []) # Whitespace only command string.
self.assertEqual(pyautogui._tokenizeCommandStr("c"), ["c"])
self.assertEqual(pyautogui._tokenizeCommandStr(" c "), ["c"])
self.assertEqual(pyautogui._tokenizeCommandStr("ccc"), ["c", "c", "c"])
self.assertEqual(pyautogui._tokenizeCommandStr(" c c c "), ["c", "c", "c"])
self.assertEqual(pyautogui._tokenizeCommandStr("clmr"), ["c", "l", "m", "r"])
self.assertEqual(pyautogui._tokenizeCommandStr("susdss"), ["su", "sd", "ss"])
self.assertEqual(pyautogui._tokenizeCommandStr(" su sd ss "), ["su", "sd", "ss"])
self.assertEqual(pyautogui._tokenizeCommandStr("clmrsusdss"), ["c", "l", "m", "r", "su", "sd", "ss"])
# Do a whole bunch of tests with random no-argument commands with random whitespace.
random.seed(42)
for i in range(100):
commands = []
commands.extend(["c"] * random.randint(0, 9))
commands.extend(["l"] * random.randint(0, 9))
commands.extend(["m"] * random.randint(0, 9))
commands.extend(["r"] * random.randint(0, 9))
for i in range(100):
commands = []
commands.extend(["c"] * random.randint(0, 9))
commands.extend(["l"] * random.randint(0, 9))
commands.extend(["m"] * random.randint(0, 9))
commands.extend(["r"] * random.randint(0, 9))
commands.extend(["su"] * random.randint(0, 9))
commands.extend(["sd"] * random.randint(0, 9))
commands.extend(["ss"] * random.randint(0, 9))
random.shuffle(commands)
commandStr = []
for command in commands:
commandStr.append(command)
commandStr.append(" " * random.randint(0, 9))
commandStr = "".join(commandStr)
self.assertEqual(pyautogui._tokenizeCommandStr(commandStr), commands)
self.assertEqual(pyautogui._tokenizeCommandStr("g10,10"), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g 10,10"), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g10 ,10"), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g10, 10"), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g 10 , 10 "), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g 10 , 10 "), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g+10,+10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g +10,+10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g+10 ,+10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g+10, +10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g +10 , +10 "), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g +10 , +10 "), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g-10,-10"), ["g", "-10", "-10"])
def test_tokenizeCommandStr(self):
self.assertEqual(pyautogui._tokenizeCommandStr(""), []) # Empty command string.
self.assertEqual(pyautogui._tokenizeCommandStr(" "), []) # Whitespace only command string.
self.assertEqual(pyautogui._tokenizeCommandStr("c"), ["c"])
self.assertEqual(pyautogui._tokenizeCommandStr(" c "), ["c"])
self.assertEqual(pyautogui._tokenizeCommandStr("ccc"), ["c", "c", "c"])
self.assertEqual(pyautogui._tokenizeCommandStr(" c c c "), ["c", "c", "c"])
self.assertEqual(pyautogui._tokenizeCommandStr("clmr"), ["c", "l", "m", "r"])
self.assertEqual(pyautogui._tokenizeCommandStr("susdss"), ["su", "sd", "ss"])
self.assertEqual(pyautogui._tokenizeCommandStr(" su sd ss "), ["su", "sd", "ss"])
self.assertEqual(pyautogui._tokenizeCommandStr("clmrsusdss"), ["c", "l", "m", "r", "su", "sd", "ss"])
# Do a whole bunch of tests with random no-argument commands with random whitespace.
random.seed(42)
for i in range(100):
commands = []
commands.extend(["c"] * random.randint(0, 9))
commands.extend(["l"] * random.randint(0, 9))
self.assertEqual(pyautogui._tokenizeCommandStr("g+10, +10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g +10 , +10 "), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g +10 , +10 "), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g-10,-10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g -10,-10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g-10 ,-10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g-10, -10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g -10 , -10 "), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g -10 , -10 "), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("d10,10"), ["d", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("d1,2g3,4"), ["d", "1", "2", "g", "3", "4"])
self.assertEqual(pyautogui._tokenizeCommandStr("w'hello'"), ["w", "hello"])
self.assertEqual(
pyautogui._tokenizeCommandStr("d1,2w'hello'g3,4"), ["d", "1", "2", "w", "hello", "g", "3", "4"]
)
self.assertEqual(pyautogui._tokenizeCommandStr("s42"), ["s", "42"])
self.assertEqual(pyautogui._tokenizeCommandStr("s42.3"), ["s", "42.3"])
self.assertEqual(pyautogui._tokenizeCommandStr("f10(c)"), ["f", "10", ["c"]])
self.assertEqual(pyautogui._tokenizeCommandStr("f10(lmr)"), ["f", "10", ["l", "m", "r"]])
self.assertEqual(pyautogui._tokenizeCommandStr("f10(f5(cc))"), ["f", "10", ["f", "5", ["c", "c"]]])
self.assertEqual(pyautogui._tokenizeCommandStr("g-10, -10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g -10 , -10 "), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g -10 , -10 "), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("d10,10"), ["d", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("d1,2g3,4"), ["d", "1", "2", "g", "3", "4"])
self.assertEqual(pyautogui._tokenizeCommandStr("w'hello'"), ["w", "hello"])
self.assertEqual(
pyautogui._tokenizeCommandStr("d1,2w'hello'g3,4"), ["d", "1", "2", "w", "hello", "g", "3", "4"]
)
self.assertEqual(pyautogui._tokenizeCommandStr("s42"), ["s", "42"])
self.assertEqual(pyautogui._tokenizeCommandStr("s42.3"), ["s", "42.3"])
self.assertEqual(pyautogui._tokenizeCommandStr("f10(c)"), ["f", "10", ["c"]])
self.assertEqual(pyautogui._tokenizeCommandStr("f10(lmr)"), ["f", "10", ["l", "m", "r"]])
self.assertEqual(pyautogui._tokenizeCommandStr("f10(f5(cc))"), ["f", "10", ["f", "5", ["c", "c"]]])
def test_tokenizeCommandStr(self):
self.assertEqual(pyautogui._tokenizeCommandStr(""), []) # Empty command string.
self.assertEqual(pyautogui._tokenizeCommandStr(" "), []) # Whitespace only command string.
self.assertEqual(pyautogui._tokenizeCommandStr("c"), ["c"])
self.assertEqual(pyautogui._tokenizeCommandStr(" c "), ["c"])
self.assertEqual(pyautogui._tokenizeCommandStr("ccc"), ["c", "c", "c"])
self.assertEqual(pyautogui._tokenizeCommandStr(" c c c "), ["c", "c", "c"])
self.assertEqual(pyautogui._tokenizeCommandStr("clmr"), ["c", "l", "m", "r"])
self.assertEqual(pyautogui._tokenizeCommandStr("susdss"), ["su", "sd", "ss"])
self.assertEqual(pyautogui._tokenizeCommandStr(" su sd ss "), ["su", "sd", "ss"])
self.assertEqual(pyautogui._tokenizeCommandStr("clmrsusdss"), ["c", "l", "m", "r", "su", "sd", "ss"])
# Do a whole bunch of tests with random no-argument commands with random whitespace.
random.seed(42)
for i in range(100):
commands = []
commands.extend(["c"] * random.randint(0, 9))
commands.extend(["l"] * random.randint(0, 9))
commands.extend(["m"] * random.randint(0, 9))
commands.extend(["r"] * random.randint(0, 9))
commands.extend(["su"] * random.randint(0, 9))
commands.extend(["sd"] * random.randint(0, 9))
commands.extend(["ss"] * random.randint(0, 9))
self.assertEqual(pyautogui._tokenizeCommandStr("d10,10"), ["d", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("d1,2g3,4"), ["d", "1", "2", "g", "3", "4"])
self.assertEqual(pyautogui._tokenizeCommandStr("w'hello'"), ["w", "hello"])
self.assertEqual(
pyautogui._tokenizeCommandStr("d1,2w'hello'g3,4"), ["d", "1", "2", "w", "hello", "g", "3", "4"]
)
self.assertEqual(pyautogui._tokenizeCommandStr("s42"), ["s", "42"])
self.assertEqual(pyautogui._tokenizeCommandStr("s42.3"), ["s", "42.3"])
self.assertEqual(pyautogui._tokenizeCommandStr("f10(c)"), ["f", "10", ["c"]])
self.assertEqual(pyautogui._tokenizeCommandStr("f10(lmr)"), ["f", "10", ["l", "m", "r"]])
self.assertEqual(pyautogui._tokenizeCommandStr("f10(f5(cc))"), ["f", "10", ["f", "5", ["c", "c"]]])
commandStr = "".join(commandStr)
self.assertEqual(pyautogui._tokenizeCommandStr(commandStr), commands)
self.assertEqual(pyautogui._tokenizeCommandStr("g10,10"), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g 10,10"), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g10 ,10"), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g10, 10"), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g 10 , 10 "), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g 10 , 10 "), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g+10,+10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g +10,+10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g+10 ,+10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g+10, +10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g +10 , +10 "), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g +10 , +10 "), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g-10,-10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g -10,-10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g-10 ,-10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g-10, -10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g -10 , -10 "), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g -10 , -10 "), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("d10,10"), ["d", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("d1,2g3,4"), ["d", "1", "2", "g", "3", "4"])
self.assertEqual(pyautogui._tokenizeCommandStr("w'hello'"), ["w", "hello"])
self.assertEqual(
pyautogui._tokenizeCommandStr("d1,2w'hello'g3,4"), ["d", "1", "2", "w", "hello", "g", "3", "4"]
self.assertEqual(pyautogui._tokenizeCommandStr(" g -10 , -10 "), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("d10,10"), ["d", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("d1,2g3,4"), ["d", "1", "2", "g", "3", "4"])
self.assertEqual(pyautogui._tokenizeCommandStr("w'hello'"), ["w", "hello"])
self.assertEqual(
pyautogui._tokenizeCommandStr("d1,2w'hello'g3,4"), ["d", "1", "2", "w", "hello", "g", "3", "4"]
)
self.assertEqual(pyautogui._tokenizeCommandStr("s42"), ["s", "42"])
self.assertEqual(pyautogui._tokenizeCommandStr("s42.3"), ["s", "42.3"])
self.assertEqual(pyautogui._tokenizeCommandStr("f10(c)"), ["f", "10", ["c"]])
self.assertEqual(pyautogui._tokenizeCommandStr("f10(lmr)"), ["f", "10", ["l", "m", "r"]])
self.assertEqual(pyautogui._tokenizeCommandStr("f10(f5(cc))"), ["f", "10", ["f", "5", ["c", "c"]]])
self.assertEqual(pyautogui._tokenizeCommandStr("g10,10"), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g 10,10"), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g10 ,10"), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g10, 10"), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g 10 , 10 "), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g 10 , 10 "), ["g", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g+10,+10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g +10,+10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g+10 ,+10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g+10, +10"), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g +10 , +10 "), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g +10 , +10 "), ["g", "+10", "+10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g-10,-10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g -10,-10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g-10 ,-10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("g-10, -10"), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g -10 , -10 "), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr(" g -10 , -10 "), ["g", "-10", "-10"])
self.assertEqual(pyautogui._tokenizeCommandStr("d10,10"), ["d", "10", "10"])
self.assertEqual(pyautogui._tokenizeCommandStr("d1,2g3,4"), ["d", "1", "2", "g", "3", "4"])
self.assertEqual(pyautogui._tokenizeCommandStr("w'hello'"), ["w", "hello"])
self.assertEqual(
pyautogui._tokenizeCommandStr("d1,2w'hello'g3,4"), ["d", "1", "2", "w", "hello", "g", "3", "4"]
)