def test_hydrates_recursive_dependencies(self, mock_clone, fs): fs_root = pathlib.Path(fs, "foo") lib = make_mbed_lib_reference(fs_root, ref_url="https://git") # Create a lib reference without touching the fs at this point, we want to mock the effects of a recursive # reference lookup and we need to assert the reference was resolved. lib2 = MbedLibReference( reference_file=(lib.source_code_path / "lib2.lib"), source_code_path=(lib.source_code_path / "lib2") ) # Here we mock the effects of a recursive reference lookup. We create a new lib reference as a side effect of # the first call to the mock. Then we create the src dir, thus resolving the lib, on the second call. mock_clone.side_effect = lambda url, dst_dir: ( make_mbed_lib_reference(pathlib.Path(dst_dir), name=lib2.reference_file.name, ref_url="https://valid2"), lib2.source_code_path.mkdir(), ) lib_refs = LibraryReferences(fs_root, ignore_paths=[fs_root / "mbed-os"]) lib_refs.resolve() self.assertTrue(lib.is_resolved()) self.assertTrue(lib2.is_resolved())
def make_mbed_lib_reference(root, name="mylib.lib", resolved=False, ref_url=None): ref_file = root / name source_dir = ref_file.with_suffix("") if not root.exists(): root.mkdir() ref_file.touch() if resolved: source_dir.mkdir() if ref_url is not None: ref_file.write_text(ref_url) return MbedLibReference(reference_file=ref_file, source_code_path=source_dir)