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_no_memoize():
fn = Mock(__name__='fn')
memoized = memoize(fn)
memoized()
memoized()
assert fn.call_count == 2
def test_memoize():
fn = Mock(__name__='fn')
memoized = memoize(fn)
memoized()
memoized()
fn.assert_called_once_with()
@memoize
@cache('.bashrc', '.bash_profile')
def get_aliases(self):
proc = Popen(['bash', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL)
return dict(
self._parse_alias(alias)
for alias in proc.stdout.read().decode('utf-8').split('\n')
if alias and '=' in alias)
@memoize
def _get_executable(script_part):
for executable in get_all_executables():
if script_part.startswith(executable):
return executable
@memoize
def get_history():
return list(_get_shell().get_history())
@memoize
def _get_destination(command):
for pattern in patterns:
found = re.findall(pattern, command.output)
if found:
if found[0] in command.script_parts:
return found[0]
@memoize
def _search(output):
for pattern in patterns:
m = pattern(output)
if m and os.path.isfile(m.group('file')):
return m
@memoize
def get_brew_path_prefix():
"""To get brew path"""
try:
return subprocess.check_output(['brew', '--prefix'],
universal_newlines=True).strip()
except Exception:
return None
@memoize
def get_history(self):
return list(self._get_history_lines())
@memoize
def _get_used_port(command):
for pattern in patterns:
matched = re.search(pattern, command.output)
if matched:
return matched.group('port')