66
77from github_dependents_info import GithubDependentsInfo
88
9+ SINGLE_PACKAGE_REPO = "nvuillam/npm-groovy-lint"
10+ SINGLE_PACKAGE_TOTAL_DOC_URL = "https://nvuillam/npm-groovy-lint"
11+ SINGLE_PACKAGE_REPO_PUBLIC_DEPENDENTS_MIN = 10
12+ MULTI_PACKAGE_REPO = "nvuillam/github-dependents-info"
13+ MULTI_PACKAGE_REPO_PUBLIC_DEPENDENTS_MIN = 10
14+
915
1016def test_collect_stats_single_package ():
1117 # Check generate single package stats file
12- repo = "nvuillam/npm-groovy-lint"
18+ repo = SINGLE_PACKAGE_REPO
1319 tmp_md_file = tempfile .gettempdir () + os .path .sep + str (uuid .uuid4 ()) + "-test-single.md"
1420 gh_deps_info = GithubDependentsInfo (
1521 repo , debug = True , sort_key = "stars" , badge_color = "pink" , markdown_file = tmp_md_file
1622 )
1723 repo_stats = gh_deps_info .collect ()
18- assert repo_stats ["public_dependents_number" ] > 10
24+ assert repo_stats ["public_dependents_number" ] > SINGLE_PACKAGE_REPO_PUBLIC_DEPENDENTS_MIN
1925
2026 md = gh_deps_info .build_markdown (file = tmp_md_file )
21- assert md .count ("\n " ) > 10
27+ assert md .count ("\n " ) > SINGLE_PACKAGE_REPO_PUBLIC_DEPENDENTS_MIN
2228 assert "pink" in md
2329 with open (tmp_md_file , encoding = "utf-8" ) as file :
2430 md_content = file .read ()
25- assert md_content .count ("\n " ) > 10
31+ assert md_content .count ("\n " ) > SINGLE_PACKAGE_REPO_PUBLIC_DEPENDENTS_MIN
2632 # Check Update README file
2733 tmp_readme_file = tempfile .gettempdir () + os .path .sep + str (uuid .uuid4 ()) + "-test-single-readme.md"
2834 with open (tmp_readme_file , "w" , encoding = "utf-8" ) as file :
2935 file .write (
3036 "<!-- gh-dependents-info-used-by-start -->" + "shouldBeReplaced" + "<!-- gh-dependents-info-used-by-end -->"
3137 )
3238
33- gh_deps_info .badges ["total_doc_url" ] = "https://nvuillam/npm-groovy-lint"
39+ gh_deps_info .badges ["total_doc_url" ] = SINGLE_PACKAGE_TOTAL_DOC_URL
3440 gh_deps_info .write_badge (tmp_readme_file , "total_doc_url" )
3541 with open (tmp_readme_file , encoding = "utf-8" ) as file :
3642 readme_content = file .read ()
3743 assert "shouldBeReplaced" not in readme_content
38- assert "nvuillam/npm-groovy-lint" in readme_content
44+ assert SINGLE_PACKAGE_REPO in readme_content
3945
4046
4147def test_collect_stats_multi_package ():
42- repo = "oxsecurity/megalinter"
48+ repo = MULTI_PACKAGE_REPO
4349 gh_deps_info = GithubDependentsInfo (repo , debug = True , sort_key = "stars" )
4450 repo_stats = gh_deps_info .collect ()
45- assert repo_stats ["public_dependents_number" ] > 100
51+ assert repo_stats ["public_dependents_number" ] > MULTI_PACKAGE_REPO_PUBLIC_DEPENDENTS_MIN
4652 tmp_md_file = tempfile .gettempdir () + os .path .sep + str (uuid .uuid4 ()) + "-test-multiple.md"
4753 md = gh_deps_info .build_markdown (file = tmp_md_file )
48- assert md .count ("\n " ) > 100
54+ assert md .count ("\n " ) > MULTI_PACKAGE_REPO_PUBLIC_DEPENDENTS_MIN
4955 with open (tmp_md_file , encoding = "utf-8" ) as file :
5056 md_content = file .read ()
51- assert md_content .count ("\n " ) > 100
57+ assert md_content .count ("\n " ) > MULTI_PACKAGE_REPO_PUBLIC_DEPENDENTS_MIN
5258
5359
5460def test_collect_stats_min_stars ():
55- repo = "nvuillam/npm-groovy-lint"
61+ repo = SINGLE_PACKAGE_REPO
5662 gh_deps_info = GithubDependentsInfo (repo , debug = True , sort_key = "stars" , min_stars = 10 )
5763 repo_stats = gh_deps_info .collect ()
64+ assert repo_stats ["public_dependents_number" ] > 1
5865 assert repo_stats ["public_dependents_number" ] < 10
5966
6067
6168def test_collect_csv ():
62- repo = "nvuillam/npm-groovy-lint"
69+ repo = SINGLE_PACKAGE_REPO
6370 with tempfile .TemporaryDirectory () as csv_directory :
6471 gh_deps_info = GithubDependentsInfo (
6572 repo , debug = True , sort_key = "stars" , min_stars = 10 , csv_directory = csv_directory
@@ -72,14 +79,18 @@ def test_collect_csv():
7279
7380
7481def test_collect_csv_multi_package ():
75- repo = "oxsecurity/megalinter"
82+ repo = MULTI_PACKAGE_REPO
7683 with tempfile .TemporaryDirectory () as csv_directory :
7784 gh_deps_info = GithubDependentsInfo (
78- repo , debug = True , sort_key = "stars" , min_stars = 10 , csv_directory = csv_directory
85+ repo , debug = True , sort_key = "stars" , min_stars = 0 , csv_directory = csv_directory
7986 )
8087 gh_deps_info .collect ()
88+ assert len (gh_deps_info .packages ) >= 2
8189 assert os .path .isfile (csv_directory + os .path .sep + f"packages_{ repo .replace ('/' , '-' )} .csv" )
90+ packages_with_entries = 0
8291 for package in gh_deps_info .packages :
8392 if package ["public_dependents_number" ] <= 0 :
8493 continue
94+ packages_with_entries += 1
8595 assert os .path .isfile (csv_directory + os .path .sep + f"dependents_{ package ['name' ].replace ('/' , '-' )} .csv" )
96+ assert packages_with_entries >= 2
0 commit comments