def __init__(self, modules, generator=None): self._file_names = [ os.path.normpath(mod.__file__.replace('.pyc', '.py')) for mod in modules ] self._modules = modules self.generator_ = generator or DefaultGenerator()
def __exit__(self, exception_type, value, tb): sys.settrace(None) for filename, functions in self.group_by_file(self._file_names, self._calls).items(): _generator = self.generator or DefaultGenerator() _generator.set_mock_substitutes(self.mock_substitutes or {}) _generator.set_extra_imports(self.extra_imports or {}) test = _generator.dump(filename, functions) if self.verbose: print('=' * 47 + ' Auger ' + '=' * 46) print(test) print('=' * 100) else: modname = get_module_name(filename) if modname == '__main__': modname = filename.replace('.py', '').capitalize() root = filename for _ in modname.split('.'): root = os.path.dirname(root) output = os.path.normpath( '%s/tests/test_%s.py' % (root or '.', modname.replace('.', '_'))) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) with open(output, 'w') as f: f.write(test) print('Auger: generated test: %s' % output)
def __init__(self, modules, generator=None, mock_substitutes={}): self._file_names = [ os.path.normpath(mod.__file__.replace('.pyc', '.py')) for mod in modules ] self._modules = modules self._generator = generator or DefaultGenerator() self._generator.set_mock_substitutes(mock_substitutes)
def __init__(self, modulesOrClasses, generator=None, verbose=False, mock_substitutes=None, extra_imports=None): self._caller = inspect.stack()[1][1] self._file_names = list( map(os.path.normpath, list(map(self._get_file, modulesOrClasses)))) self._generator = generator or DefaultGenerator() self._generator.set_mock_substitutes(mock_substitutes or {}) self._generator.set_extra_imports(extra_imports or {}) self.modulesOrClasses = set(modulesOrClasses) self.verbose = verbose
def __init__(self, modulesOrClasses, generator=None, verbose=False): self._caller = inspect.stack()[1][1] self._file_names = map(os.path.normpath, map(self._get_file, modulesOrClasses)) self.generator_ = generator or DefaultGenerator() self.verbose = verbose