def test_make_clean(): fs.cd("lib/labm8/data/test/makeproj") make.make() assert fs.isfile("foo") assert fs.isfile("foo.o") make.clean() assert not fs.isfile("foo") assert not fs.isfile("foo.o") fs.cdpop()
def make(target="all", dir=".", **kwargs): """ Run make. Arguments: target (str, optional): Name of the target to build. Defaults to "all". dir (str, optional): Path to directory containing Makefile. **kwargs (optional): Any additional arguments to be passed to system.run(). Returns: (int, str, str): The first element is the return code of the make command. The second and third elements are the stdout and stderr of the process. Raises: NoMakefileError: In case a Makefile is not found in the target directory. NoTargetError: In case the Makefile does not support the requested target. MakeError: In case the target rule fails. """ if not fs.isfile(fs.path(dir, "Makefile")): raise NoMakefileError("No makefile in '{}'".format(fs.abspath(dir))) fs.cd(dir) # Default parameters to system.run() if "timeout" not in kwargs: kwargs["timeout"] = 300 ret, out, err = system.run(["make", target], **kwargs) fs.cdpop() if ret > 0: if re.search(_BAD_TARGET_RE, err): raise NoTargetError("No rule for target '{}'".format(target)) else: raise MakeError("Target '{}' failed".format(target)) raise MakeError("Failed") return ret, out, err
def test_cd(): cwd = os.getcwd() new = fs.abspath("..") assert new == fs.cd("..") assert new == os.getcwd() assert cwd == fs.cdpop() assert cwd == os.getcwd() assert cwd == fs.cdpop() assert cwd == os.getcwd() assert cwd == fs.cdpop() assert cwd == os.getcwd()
def unpack_archive(*components, **kwargs) -> str: """ Unpack a compressed archive. Arguments: *components (str[]): Absolute path. **kwargs (dict, optional): Set "compression" to compression type. Default: bz2. Set "dir" to destination directory. Defaults to the directory of the archive. Returns: str: Path to directory. """ path = fs.abspath(*components) compression = kwargs.get("compression", "bz2") dir = kwargs.get("dir", fs.dirname(path)) fs.cd(dir) tar = tarfile.open(path, "r:" + compression) tar.extractall() tar.close() fs.cdpop() return dir