def test_colorize_file(key, file_path, colorizable_files, xs_LS_COLORS): """test proper file codes with symlinks colored normally""" ffp = colorizable_files + "/" + file_path stat_result = os.lstat(ffp) color_token, color_key = color_file(ffp, stat_result) assert color_key == key, "File classified as expected kind" assert color_token == file_color_tokens[key], "Color token is as expected"
def test_colorize_file(key, file_path, colorizable_files, xonsh_builtins_LS_COLORS): xonsh_builtins_LS_COLORS.__xonsh__.shell.shell.styler = ( XonshStyle() ) # default style ffp = colorizable_files + "/" + file_path mode = (os.lstat(ffp)).st_mode color_token, color_key = color_file(ffp, mode) assert color_key == key, "File classified as expected kind" assert color_token == file_color_tokens[key], "Color token is as expected"
def test_colorize_file_symlink(key, file_path, colorizable_files, xs_LS_COLORS): """test proper file codes with symlinks colored target.""" xs_LS_COLORS.env["LS_COLORS"]["ln"] = "target" ffp = colorizable_files + "/" + file_path + "_symlink" stat_result = os.lstat(ffp) assert stat.S_ISLNK(stat_result.st_mode) _, color_key = color_file(ffp, stat_result) try: tar_stat_result = os.stat(ffp) # stat the target of the link tar_ffp = str(pathlib.Path(ffp).resolve()) _, tar_color_key = color_file(tar_ffp, tar_stat_result) if tar_color_key.startswith("*"): tar_color_key = ( "fi" # all the *.* zoo, link is colored 'fi', not target type. ) except FileNotFoundError: # orphan symlinks always colored 'or' tar_color_key = "or" # Fake if for missing file assert color_key == tar_color_key, "File classified as expected kind, via symlink"
def test_colorize_file_ca(xs_LS_COLORS, monkeypatch): def mock_os_listxattr(*args, **kwards): return ["security.capability"] monkeypatch.setattr(xonsh.pyghooks, "os_listxattr", mock_os_listxattr) with TemporaryDirectory() as tmpdir: file_path = tmpdir + "/cap_file" open(file_path, "a").close() os.chmod( file_path, stat.S_IRWXU ) # ca overrides ex, leave file deletable on Windows color_token, color_key = color_file(file_path, os.lstat(file_path)) assert color_key == "ca"