Only subtract excluded files from repos that were counted
This commit is contained in:
1 parent
9f76bf6c41
commit
26a9207daa
3 files changed
+49
-21
No files matched your search
@@ -93,6 +93,27 @@ def test_first_run_writes_the_stats_into_the_profile_readme(gitea, monkeypatch,
|
||||
assert "README.md updated successfully." in capsys.readouterr().err
|
||||
|
||||
|
||||
def test_excluded_file_in_a_skipped_repo_does_not_lower_other_repos(gitea, monkeypatch):
|
||||
# website (which holds the excluded aframe.js) can't be read, so none of
|
||||
# its bytes were counted and none should be subtracted.
|
||||
serve_account(gitea, monkeypatch)
|
||||
gitea.add("GET", WEBSITE_LANGS, {"message": "token scope is limited"}, status=403)
|
||||
gitea.add("GET", SCRIPTS_LANGS, {"Python": 3000, "JavaScript": 1000})
|
||||
run_main(monkeypatch)
|
||||
# Total 4000 -> Python 75.0% (37 blocks), JavaScript 25.0% (12 blocks)
|
||||
assert pushed_readme(gitea) == (
|
||||
"# Hi there\n\n"
|
||||
"<!--LANG_STATS_START-->\n"
|
||||
"## 📊 Languages\n"
|
||||
+ "█" * 37
|
||||
+ " Python 75.0%\\\n"
|
||||
+ "█" * 12
|
||||
+ " JavaScript 25.0%\n"
|
||||
"<!--LANG_STATS_END-->\n\n"
|
||||
"Thanks for visiting\n"
|
||||
)
|
||||
|
||||
|
||||
def test_first_run_saves_repo_timestamps_without_the_profile_repo(
|
||||
gitea, monkeypatch, state_file
|
||||
):
|
||||
|
||||
+13
-13
@@ -118,7 +118,9 @@ def test_response_that_is_not_a_dict_is_skipped(gitea):
|
||||
# --- subtract_excluded_files ------------------------------------------------
|
||||
|
||||
|
||||
def test_every_excluded_file_size_is_subtracted_from_its_language(gitea, monkeypatch):
|
||||
def test_only_this_repos_excluded_files_are_subtracted(gitea, monkeypatch):
|
||||
# The game repo's aframe.js isn't registered with the fake server, so
|
||||
# fetching it while handling the guide repo would fail this test.
|
||||
monkeypatch.setattr(
|
||||
language_stats,
|
||||
"EXCLUDE_FILES",
|
||||
@@ -128,14 +130,12 @@ def test_every_excluded_file_size_is_subtracted_from_its_language(gitea, monkeyp
|
||||
("guide", "home/Vue3-v.5.html", "HTML"),
|
||||
],
|
||||
)
|
||||
gitea.add("GET", AFRAME_FILE, {"size": 300})
|
||||
gitea.add("GET", VUE4_FILE, {"size": 100})
|
||||
gitea.add("GET", VUE5_FILE, {"size": 150})
|
||||
totals = {"JavaScript": 1000, "HTML": 500, "Python": 400}
|
||||
assert subtract_excluded_files(get_session(), totals) == {
|
||||
"JavaScript": 700,
|
||||
langs = {"HTML": 500, "CSS": 400}
|
||||
assert subtract_excluded_files(get_session(), "guide", langs) == {
|
||||
"HTML": 250,
|
||||
"Python": 400,
|
||||
"CSS": 400,
|
||||
}
|
||||
|
||||
|
||||
@@ -144,10 +144,10 @@ def test_subtracting_an_excluded_file_never_goes_below_zero(gitea, monkeypatch):
|
||||
language_stats, "EXCLUDE_FILES", [("game", "static/aframe.js", "JavaScript")]
|
||||
)
|
||||
gitea.add("GET", AFRAME_FILE, {"size": 5000})
|
||||
totals = {"JavaScript": 1000, "Python": 400}
|
||||
assert subtract_excluded_files(get_session(), totals) == {
|
||||
langs = {"JavaScript": 1000, "CSS": 400}
|
||||
assert subtract_excluded_files(get_session(), "game", langs) == {
|
||||
"JavaScript": 0,
|
||||
"Python": 400,
|
||||
"CSS": 400,
|
||||
}
|
||||
|
||||
|
||||
@@ -156,8 +156,8 @@ def test_excluded_file_that_no_longer_exists_is_ignored(gitea, monkeypatch):
|
||||
language_stats, "EXCLUDE_FILES", [("game", "static/aframe.js", "JavaScript")]
|
||||
)
|
||||
gitea.add("GET", AFRAME_FILE, {"message": "not found"}, status=404)
|
||||
totals = {"JavaScript": 1000}
|
||||
assert subtract_excluded_files(get_session(), totals) == {"JavaScript": 1000}
|
||||
langs = {"JavaScript": 1000}
|
||||
assert subtract_excluded_files(get_session(), "game", langs) == {"JavaScript": 1000}
|
||||
|
||||
|
||||
def test_network_error_on_an_excluded_file_is_ignored(gitea, monkeypatch):
|
||||
@@ -165,8 +165,8 @@ def test_network_error_on_an_excluded_file_is_ignored(gitea, monkeypatch):
|
||||
language_stats, "EXCLUDE_FILES", [("game", "static/aframe.js", "JavaScript")]
|
||||
)
|
||||
gitea.add_error("GET", AFRAME_FILE, requests.ConnectionError("connection reset"))
|
||||
totals = {"JavaScript": 1000}
|
||||
assert subtract_excluded_files(get_session(), totals) == {"JavaScript": 1000}
|
||||
langs = {"JavaScript": 1000}
|
||||
assert subtract_excluded_files(get_session(), "game", langs) == {"JavaScript": 1000}
|
||||
|
||||
|
||||
# --- generate_markdown --------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user