Skip to content

Commit

Permalink
add --test flag for test suite and debugging purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
AshirGuptash committed Apr 24, 2021
1 parent c41580b commit ae9e5b2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
3 changes: 2 additions & 1 deletion dyc/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@


class Builder(object):
def __init__(self, filename, config, placeholders=False):
def __init__(self, filename, config, placeholders=False, test=False):
self.filename = filename
self.config = config
self.placeholders = placeholders
self.test = test

details = dict()

Expand Down
33 changes: 22 additions & 11 deletions dyc/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def extract_and_set_information(self, filename, start, line, length):
config=self.config,
leading_space=get_leading_whitespace(initial_line),
placeholders=self.placeholders,
test=self.test
)

def extract_classes(self, line):
Expand All @@ -167,7 +168,6 @@ def prompts(self):

def _class_interface_gen(self):
# For each ClassInterface object in details[filename][class_name]
pass
if not self.details:
yield None
for filename, func_pack in self.details.items():
Expand Down Expand Up @@ -227,7 +227,6 @@ def _get_name(self, line):
if name:
return name

# Dumb duplicate of _is_class
def _is_class(self, line):
"""
A predicate method that checks if a line is a
Expand All @@ -245,7 +244,7 @@ class ClassFormatter:
formatted_string = "{open}{break_after_open}{class_docstring}{break_after_docstring}{empty_line}{parents_format}{break_before_close}{close}"
fmt = BlankFormatter()

def format(self):
def format(self, test):
"""
Public formatting method that executes a pattern of methods to
complete the process
Expand All @@ -256,6 +255,7 @@ def format(self):
self.result = self.fmt.format(self.formatted_string, **self.class_format)
self.add_indentation()
self.polish()
self.test = test

def wrap_strings(self, words):
"""
Expand Down Expand Up @@ -384,11 +384,16 @@ def confirm(self, polished):

try:
result = "\n".join(class_split)
message = click.edit(
"## CONFIRM: MODIFY DOCSTRING BETWEEN START AND END LINES ONLY\n\n"
+ result
)
message = result if message == None else "\n".join(message.split("\n")[2:])

# If running an automated test
if self.test:
message = result
else:
message = click.edit(
"## CONFIRM: MODIFY DOCSTRING BETWEEN START AND END LINES ONLY\n\n"
+ result
)
message = result if message == None else "\n".join(message.split("\n")[2:])
except:
print("Quitting the program in the editor terminates the process. Thanks")
sys.exit()
Expand Down Expand Up @@ -432,6 +437,7 @@ def __init__(
config,
leading_space,
placeholders,
test,
):
self.plain = plain
self.name = name
Expand All @@ -444,11 +450,12 @@ def __init__(
self.config = config
self.leading_space = leading_space
self.placeholders = placeholders
self.test = test

def prompt(self):
self._prompt_docstring()
self._prompt_parents()
self.format()
self.format(test=self.test)

def _prompt_docstring(self):
"""
Expand Down Expand Up @@ -507,10 +514,14 @@ def extract(self):
]
except:
pass
self.parents = [parent for parent in self.parents if parent != '']
self.parents = [parent for parent in self.parents if parent != ""]

def sanitize(self):
"""
Sanitizes classes to validate all classes are correct
"""
return map(lambda parent: re.findall(r"[a-zA-Z0-9_]+", parent)[0], self.parents)
# Updated filter function to remove invalid parent names
return list(filter(
lambda parent: not re.findall(r"[^a-zA-Z0-9_]", parent),
self.parents
))
5 changes: 3 additions & 2 deletions dyc/dyc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ def main(config):
@main.command()
@click.option("--placeholders", is_flag=True, default=False)
@click.argument("files", nargs=-1, type=click.Path(exists=True), required=False)
@click.option("-t", "--test", required=False, default=False, is_flag=True)
@config
def start(config, files, placeholders):
def start(config, files, placeholders, test):
"""
This is the entry point of starting DYC for the whole project.
When you run `dyc start`. ParsedConfig will wrap all the
Expand All @@ -44,7 +45,7 @@ def start(config, files, placeholders):
"""
if files:
config.plain["file_list"] = list(files)
dyc = DYC(config.plain, placeholders=placeholders)
dyc = DYC(config.plain, placeholders=placeholders, test=test)
dyc.prepare()
dyc.process_methods()
dyc.process_top()
Expand Down
9 changes: 5 additions & 4 deletions dyc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@


class DYC(Processor):
def __init__(self, config, details=None, placeholders=False):
def __init__(self, config, details=None, placeholders=False, test=False):
self.config = config
self.placeholders = placeholders
self.test = test

def process_methods(self, diff_only=False, changes=[]):
"""
Expand Down Expand Up @@ -46,7 +47,7 @@ def process_methods(self, diff_only=False, changes=[]):
method_cnf = fmt.get("method", {})
method_cnf["arguments"] = fmt.get("arguments")
builder = MethodBuilder(
filename, method_cnf, placeholders=self.placeholders
filename, method_cnf, placeholders=self.placeholders, test=self.test
)
builder.initialize(change=change)
builder.prompts()
Expand All @@ -64,7 +65,7 @@ def process_classes(self):
classes_cnf = fmt.get("class", {})
classes_cnf["parents"] = fmt.get("parents")
builder = ClassBuilder(
filename, classes_cnf, placeholders=self.placeholders
filename, classes_cnf, placeholders=self.placeholders, test=self.test
)
builder.initialize()
builder.prompts()
Expand All @@ -81,7 +82,7 @@ def process_top(self, diff_only=False):
extension = get_extension(filename)
fmt = self.formats.get(extension)
top_cnf = fmt.get("top", {})
builder = TopBuilder(filename, top_cnf, placeholders=self.placeholders)
builder = TopBuilder(filename, top_cnf, placeholders=self.placeholders, test=self.test)
builder.prompts()
builder.apply()
builder.clear(filename)

0 comments on commit ae9e5b2

Please sign in to comment.