def scan_cpp(filename, already=None): if not already: already = {} if filename in already: return if files.copy(filename) or rules.match(filename): return [filename] already[filename] = None path = os.path.split(filename)[0] file = read(filename) if file is None: raise IOError deps = [filename] match = rx_include.search(file) build_incpaths = files.readlines("build-includes") or [] incpaths = ["", path] + build_incpaths while match: inctype, inc = match.groups() incs = [] if inctype == "<" else [inc] for incpath in incpaths: try: incs = scan_cpp(os.path.join(incpath, inc), already) except IOError: continue if incs is not None: break deps.extend(incs or []) match = rx_include.search(file, match.end()) return deps
def test_readlines(self): f = files.open.return_value self.assertIsInstance(f.readline.return_value, MagicMock) # not configured self.assertIsNone(f.readline.side_effect) f.readlines.return_value = ['chunk1\n', 'chunk2\n', '\n'] # mock out readlines() self.assertEqual(files.readlines('pathname'), ['chunk1\n', 'chunk2\n', '\n']) files.open.assert_called_once_with('pathname', 'rb') f.readlines.assert_called_once_with()
def readlist(filename, dirname=None): list = files.readlines(filename) if list is None: raise IOError if dirname: list = [os.path.join(dirname, i) for i in list] # list = map(os.path.normpath, list) if debug: print("readlist(%s,%s)=>%s" % (filename, dirname, list)) return list