def test_import_handler_imports_content_with_respect_to_regex(self, monkeypatch): handlerInput = "import fakepath.py (\t*this$)" def FileHelperMock(*args): return "\t\tthat\n\t\tthis not\n\t\tthis" def extractMock(content, regex): if content not in "\t\tthat\n\t\tthis not\n\t\tthis" \ or regex not in "(\t*this$)": raise AssertionError return "\t\tthis" monkeypatch.setattr(helper, 'load', FileHelperMock) monkeypatch.setattr(helper, 'extract', extractMock) x = Import() x.handle(handlerInput) assert x.output(wrapper=None) == "\t\tthis"
def test_import_handler_extracts_path_and_regex(self, monkeypatch): def extractmock(*args): pass def filehelpermock(*args): pass monkeypatch.setattr(helper, 'extract', extractmock) monkeypatch.setattr(helper, 'load', filehelpermock) fakepath = "faketest.py" fakeregex = "(^some [arbitraty] regex)" handlerInput="import {0} {1}".format(fakepath, fakeregex) importhandler = Import() importhandler.handle(handlerInput) x = importhandler.script_name y = importhandler.regex assert x == fakepath assert y == fakeregex