Skip to content

Commit

Permalink
Blacked .tools
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther committed Oct 18, 2023
1 parent e756c5f commit edec816
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 309 deletions.
141 changes: 87 additions & 54 deletions .tools/pre_validate/test/test_pre_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,106 @@
import pre_validate


@pytest.mark.parametrize("file_contents,expected_error_count", [
("Test file contents.\n" \
"This URL is not allowed: http://alpha-docs-aws" + ".amazon.com/test\n" \
"And neither is this one:\n" \
"https://integ-docs-aws" + ".amazon.com/something-else\n" \
"But that's it for denied words.", 2),
("This string has no denied words.\n"
"And neither does this one.", 0)
])
@pytest.mark.parametrize(
"file_contents,expected_error_count",
[
(
"Test file contents.\n"
"This URL is not allowed: http://alpha-docs-aws" + ".amazon.com/test\n"
"And neither is this one:\n"
"https://integ-docs-aws" + ".amazon.com/something-else\n"
"But that's it for denied words.",
2,
),
("This string has no denied words.\n" "And neither does this one.", 0),
],
)
def test_verify_no_deny_list_words(file_contents, expected_error_count):
"""Test that file contents that contain disallowed words are counted as errors."""
error_count = pre_validate.verify_no_deny_list_words(file_contents, "location")
assert error_count == expected_error_count


@pytest.mark.parametrize("file_contents,expected_error_count", [
("This sentence has a hidAKAAIOS" + "FODNN7EXAMPLEden secret key.", 1),
("This sentence has a hidAKIAIOSFO" + "DNN7EXAMPLEden example key.", 0),
("This sentence has nothing interesting about it at all.", 0),
("This could be a secret key, I guess: aws/monitoring/mo"
"del/DeleteAlarmsRequbbb\n"
"And so could this: TargetTrackingScalingP" + "olicy1234567891234\n"
"Not this: wJalrXUtnFEMI/K7MDENG/bPxR" + "fiCYEXAMPLEKEY is allowed!", 2),
("Normal_file_name.py", 0),
("Something AppStreamUsageReportsCFNGl" + "ueAthenaAccess.cs", 0),
("Something AppStreamUsageReportsCFNGlue" + "AtNotAllowed.py", 1),
])
@pytest.mark.parametrize(
"file_contents,expected_error_count",
[
("This sentence has a hidAKAAIOS" + "FODNN7EXAMPLEden secret key.", 1),
("This sentence has a hidAKIAIOSFO" + "DNN7EXAMPLEden example key.", 0),
("This sentence has nothing interesting about it at all.", 0),
(
"This could be a secret key, I guess: aws/monitoring/mo"
"del/DeleteAlarmsRequbbb\n"
"And so could this: TargetTrackingScalingP" + "olicy1234567891234\n"
"Not this: wJalrXUtnFEMI/K7MDENG/bPxR" + "fiCYEXAMPLEKEY is allowed!",
2,
),
("Normal_file_name.py", 0),
("Something AppStreamUsageReportsCFNGl" + "ueAthenaAccess.cs", 0),
("Something AppStreamUsageReportsCFNGlue" + "AtNotAllowed.py", 1),
],
)
def test_verify_no_secret_keys(file_contents, expected_error_count):
"""Test that file contents that contain 20- or 40-character strings and are
not in the allowed list are counted as errors."""
error_count = pre_validate.verify_no_secret_keys(file_contents, "location")
assert error_count == expected_error_count


@pytest.mark.parametrize("file_contents,expected_error_count", [
("snippet" + "-start:[this.is.a.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.snippet.tag]", 0),
("snippet" + "-start:[this.is.a.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.different.snippet.tag]", 2),
("snippet" + "-start:[this.is.a.snippet.tag]\n"
"This is not code.", 1),
("This is not code.\n"
"snippet" + "-end:[this.is.a.snippet.tag]", 1),
("snippet" + "-start:[this.is.a.snippet.tag]\n"
"snippet" + "-start:[this.is.a.different.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.snippet.tag]\n"
"snippet" + "-end:[this.is.a.different.snippet.tag]\n", 0),
("snippet" + "-start:[this.is.a.snippet.tag]\n"
"snippet" + "-start:[this.is.a.different.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.different.snippet.tag]\n"
"snippet" + "-end:[this.is.a.snippet.tag]\n", 0),
("snippet" + "-start:[this.is.a.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.snippet.tag.with.extra.stuff]\n", 2),
("snippet" + "-start:[this.is.a.snippet.tag]\n"
"snippet" + "-start:[this.is.a.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.snippet.tag]\n", 1),
("snippet" + "-start:[this.is.a.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.snippet.tag]\n"
"snippet" + "-end:[this.is.a.snippet.tag]\n", 1),
])
@pytest.mark.parametrize(
"file_contents,expected_error_count",
[
(
"snippet" + "-start:[this.is.a.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.snippet.tag]",
0,
),
(
"snippet" + "-start:[this.is.a.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.different.snippet.tag]",
2,
),
("snippet" + "-start:[this.is.a.snippet.tag]\n" "This is not code.", 1),
("This is not code.\n" "snippet" + "-end:[this.is.a.snippet.tag]", 1),
(
"snippet" + "-start:[this.is.a.snippet.tag]\n"
"snippet" + "-start:[this.is.a.different.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.snippet.tag]\n"
"snippet" + "-end:[this.is.a.different.snippet.tag]\n",
0,
),
(
"snippet" + "-start:[this.is.a.snippet.tag]\n"
"snippet" + "-start:[this.is.a.different.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.different.snippet.tag]\n"
"snippet" + "-end:[this.is.a.snippet.tag]\n",
0,
),
(
"snippet" + "-start:[this.is.a.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.snippet.tag.with.extra.stuff]\n",
2,
),
(
"snippet" + "-start:[this.is.a.snippet.tag]\n"
"snippet" + "-start:[this.is.a.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.snippet.tag]\n",
1,
),
(
"snippet" + "-start:[this.is.a.snippet.tag]\n"
"This is not code.\n"
"snippet" + "-end:[this.is.a.snippet.tag]\n"
"snippet" + "-end:[this.is.a.snippet.tag]\n",
1,
),
],
)
def test_verify_snippet_start_end(file_contents, expected_error_count):
"""Test that various kinds of mismatched snippet-start and -end tags are
counted correctly as errors."""
Expand Down
Loading

0 comments on commit edec816

Please sign in to comment.