def test_with_version_all_within(semver_exec): all_within_range = [ "2.0.0", "2.1.0", "2.1.1", "3.0.0-alpha", "3.0.0-beta", "3.0.0", ] command_args = [semver_command, abitrary_range] command_args.extend(all_within_range) exit_code, output_lines, _ = exec_any_cli(semver_exec, command_args) assert exit_code == 0 assert output_lines == all_within_range
def test_any_bad_parsing_causes_error_message(semver_exec): badly_written_versions = [ "1.0.0", "2asf.0.0", "2.1.0", "2.1.1", "3.0.0-alpha", "3.0.0-beta", "***---...3.0.0", ] command_args = ["order"] command_args.extend(badly_written_versions) exit_code, _, error_lines = exec_any_cli(semver_exec, command_args) assert exit_code != 0 assert find_in_any_lines(re.compile("^error:.*"), error_lines)
def test_order_arguments(semver_exec): ordered_versions = [ "1.0.0", "2.0.0", "2.1.0", "2.1.1", "3.0.0-alpha", "3.0.0-beta", "3.0.0", ] randomised_versions = ordered_versions.copy() random.shuffle(randomised_versions) command_args = ["order"] command_args.extend(randomised_versions) _, output_lines, _ = exec_any_cli(semver_exec, command_args) assert output_lines == ordered_versions
def test_with_some_out_of_range(semver_exec): some_is_out_of_range = [ "2.0.0", "0.12.0", "2.1.0", "2.1.1", "3.0.0-alpha", "1.0.0-beta", "3.0.0", ] within_range = [ "2.0.0", "2.1.0", "2.1.1", "3.0.0-alpha", "3.0.0", ] command_args = [semver_command, abitrary_range] command_args.extend(some_is_out_of_range) _, output_lines, _ = exec_any_cli(semver_exec, command_args) assert output_lines == within_range
def test_command_is_documented(semver_exec): _, output_lines, _ = exec_any_cli(semver_exec, ["--help"]) assert find_in_any_lines("^\\s+{}".format(semver_command), output_lines)
def test_fails_with_invalid_version_strings(semver_exec): some_is_invalid = ["abc", "1.0.0", "b.a.c", "0.1.0-pre.1"] command_args = [semver_command, abitrary_range] command_args.extend(some_is_invalid) exit_code, _, _ = exec_any_cli(semver_exec, command_args) assert exit_code == 1
def test_when_running_no_option_then_prints_usage(semver_exec): exit_code, _, error_lines = exec_any_cli(semver_exec, []) assert exit_code == 1 assert error_lines[0] == "error: command required, please use --help"
def test_returns_version(semver_exec): exit_code, output_lines, _ = exec_any_cli(semver_exec, ["--version"]) assert exit_code == 0 assert output_lines[0] == "0.1.0"
def test_when_calling_with_help_prints_options(semver_exec): exit_code, output_lines, _ = exec_any_cli(semver_exec, ["--help"]) assert exit_code == 0 assert find_in_any_lines(re.compile("--help"), output_lines) assert find_in_any_lines(re.compile("--version"), output_lines)