-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: decouple functions & restructure folders for better organiz…
…ation * fix: solve tests failing because using a class method directly in tests
- Loading branch information
Showing
4 changed files
with
79 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Global utils | ||
""" | ||
|
||
import re | ||
from typing import List | ||
|
||
|
||
def find_tutor_misspelled(command: str): | ||
""" | ||
This function takes a command and looks if it has the word 'tutor' misspelled | ||
Args: | ||
command (str): Command to be reviewed | ||
Return: | ||
If its found the word 'tutor' misspelled is returned True | ||
""" | ||
return re.match(r"[tT](?:[oru]{3}|[oru]{2}[rR]|[oru]u?)", command) | ||
|
||
|
||
def create_regex_from_array(arr: list[str]): | ||
""" | ||
This functions compiles a new regex turning taking care of | ||
escaping special characters | ||
Args: | ||
arr (list[str]): String that would be used to create a new regex | ||
Return: | ||
A new compiled regex pattern that can be used for comparisons | ||
""" | ||
escaped_arr = [re.escape(item) for item in arr] | ||
regex_pattern = "|".join(escaped_arr) | ||
return re.compile(regex_pattern) | ||
|
||
|
||
# Was necessary to use List from typing because of failing tests in Python 3.8 | ||
# https://stackoverflow.com/questions/75202610/typeerror-type-object-is-not-subscriptable-python | ||
def split_string(string: str, split_by: List[str]): | ||
""" | ||
Takes a string that is wanted to be split according to some | ||
other strings received in a list | ||
Args: | ||
string (str): String that will be split | ||
split_by (list[str]): Array of strings which will be used to split the string | ||
Return: | ||
The string split into an array | ||
""" | ||
return re.split(create_regex_from_array(split_by), string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,5 @@ | ||
""" | ||
File of constant variables | ||
""" | ||
import re | ||
|
||
COMMAND_CHAINING_OPERATORS = ["&&", "&", "||", "|", ";"] | ||
|
||
|
||
def find_tutor_misspelled(command: str): | ||
""" | ||
This function takes a command and looks if it has the word 'tutor' misspelled | ||
Args: | ||
command (str): Command to be reviewed | ||
Return: | ||
If its found the word 'tutor' misspelled is returned True | ||
""" | ||
return re.match(r'[tT](?:[oru]{3}|[oru]{2}[rR]|[oru]u?)', command) | ||
|
||
|
||
def create_regex_from_array(arr: list[str]): | ||
""" | ||
This functions compiles a new regex turning taking care of | ||
escaping special characters | ||
Args: | ||
arr (list[str]): String that would be used to create a new regex | ||
Return: | ||
A new compiled regex pattern that can be used for comparisons | ||
""" | ||
escaped_arr = [re.escape(item) for item in arr] | ||
regex_pattern = "|".join(escaped_arr) | ||
return re.compile(regex_pattern) |