def test_has_command_custom_commands(state): with setup_workspace(): update_bash_history_info() has_command(state, "(a|b)+", "a and b are the best letters", commands=["old command"])
def test_prepare_validation(state): state.force_diagnose = True with setup_workspace(): update_bash_history_info() prepare_validation(state, ["ls", "echo abc"]) has_command(state, "ls", "good job") has_command(state, "echo.*c", "well done")
def test_update_bash_history_info(): with setup_workspace() as (bash_history_path, bash_history_info_path): update_bash_history_info() assert Path(bash_history_info_path.name).read_text() == "0" Path(bash_history_path.name).write_text("a command\nanother one") update_bash_history_info() assert Path(bash_history_info_path.name).read_text() == "2"
def test_has_command_fixed(state): with setup_workspace() as (bash_history_path, bash_history_info_path): update_bash_history_info() Path(bash_history_path.name).write_text("(a|b)+") has_command(state, "(a|b)+", "a and b are the best letters", fixed=True)
def test_get_bash_history(): with setup_workspace() as (bash_history_path, bash_history_info_path): Path(bash_history_path.name).write_text("old command") update_bash_history_info() assert get_bash_history() == [] Path(bash_history_path.name).write_text( "old command\na command\nanother one") assert get_bash_history() == ["a command\n", "another one"]
def test_update_bash_history_info_custom_location(): with setup_workspace() as (bash_history_path, bash_history_info_path): with tempfile.NamedTemporaryFile() as custom_bash_history_path: update_bash_history_info( bash_history_path=custom_bash_history_path.name) assert Path(bash_history_info_path.name).read_text() == "0" Path(custom_bash_history_path.name).write_text( "a command\nanother one") update_bash_history_info( bash_history_path=custom_bash_history_path.name) assert Path(bash_history_info_path.name).read_text() == "2"
def test_get_bash_history_custom_location(): with setup_workspace(): with tempfile.NamedTemporaryFile() as custom_bash_history_path: Path(custom_bash_history_path.name).write_text("old command") update_bash_history_info( bash_history_path=custom_bash_history_path.name) assert (get_bash_history( bash_history_path=custom_bash_history_path.name) == []) Path(custom_bash_history_path.name).write_text( "old command\na command\nanother one") assert get_bash_history( bash_history_path=custom_bash_history_path.name) == [ "a command\n", "another one" ]
def test_has_command_failure(state): with setup_workspace() as (bash_history_path, bash_history_info_path): update_bash_history_info() Path(bash_history_path.name).write_text("wrong") with pytest.raises(TF, match="a and b"): has_command(state, "(a|b)+", "a and b are the best letters")
def test_has_command_no_commands(state): with setup_workspace(): update_bash_history_info() with pytest.raises(TF, match="didn't find any"): has_command(state, "(a|b)+", "a and b are the best letters")