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
def create_copy_of_module(module, new_name): | |
"""Decorator to copy a module for mock testing without side effects. | |
module and new_name are strings of the module to copy, and the name that | |
the copy will be called so that it can then be imported. | |
""" | |
def wrap(f): | |
def wrapped_f(*args): | |
orig_spec = importlib.util.find_spec(module) | |
new = importlib.util.module_from_spec(orig_spec) |
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
def smart_substr(in_str, terminate='...'): | |
if len(in_str) <= 30: | |
return in_str + terminate | |
else: | |
if in_str[30] != ' ': | |
return ' '.join(in_str[0:30].split()[:-1]) + terminate | |
else: | |
return in_str[0:30] + terminate |