-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_gh_dependents_info.py
67 lines (56 loc) · 2.7 KB
/
test_gh_dependents_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Tests for gh_dependents_info"""
import os
import tempfile
import uuid
from github_dependents_info import GithubDependentsInfo
def test_collect_stats_single_package():
repo = "nvuillam/npm-groovy-lint"
gh_deps_info = GithubDependentsInfo(repo, debug=True, sort_key="stars", badge_color="pink")
repo_stats = gh_deps_info.collect()
assert repo_stats["public_dependents_number"] > 10
tmp_md_file = tempfile.gettempdir() + os.path.sep + str(uuid.uuid4()) + "-test-single.md"
md = gh_deps_info.build_markdown(file=tmp_md_file)
assert md.count("\n") > 10
assert "pink" in md
with open(tmp_md_file, encoding="utf-8") as file:
md_content = file.read()
assert md_content.count("\n") > 10
def test_collect_stats_multi_package():
repo = "oxsecurity/megalinter"
gh_deps_info = GithubDependentsInfo(repo, debug=True, sort_key="stars")
repo_stats = gh_deps_info.collect()
assert repo_stats["public_dependents_number"] > 100
tmp_md_file = tempfile.gettempdir() + os.path.sep + str(uuid.uuid4()) + "-test-multiple.md"
md = gh_deps_info.build_markdown(file=tmp_md_file)
assert md.count("\n") > 100
with open(tmp_md_file, encoding="utf-8") as file:
md_content = file.read()
assert md_content.count("\n") > 100
def test_collect_stats_min_stars():
repo = "nvuillam/npm-groovy-lint"
gh_deps_info = GithubDependentsInfo(repo, debug=True, sort_key="stars", min_stars=10)
repo_stats = gh_deps_info.collect()
assert repo_stats["public_dependents_number"] < 10
def test_collect_csv():
repo = "nvuillam/npm-groovy-lint"
with tempfile.TemporaryDirectory() as csv_directory:
gh_deps_info = GithubDependentsInfo(
repo, debug=True, sort_key="stars", min_stars=10, csv_directory=csv_directory
)
gh_deps_info.collect()
assert os.path.isfile(csv_directory + os.path.sep + f"packages_{repo.replace('/','-')}.csv")
assert os.path.isfile(
csv_directory + os.path.sep + f"dependents_{gh_deps_info.packages[0]['name'].replace('/','-')}.csv"
)
def test_collect_csv_multi_package():
repo = "oxsecurity/megalinter"
with tempfile.TemporaryDirectory() as csv_directory:
gh_deps_info = GithubDependentsInfo(
repo, debug=True, sort_key="stars", min_stars=10, csv_directory=csv_directory
)
gh_deps_info.collect()
assert os.path.isfile(csv_directory + os.path.sep + f"packages_{repo.replace('/','-')}.csv")
for package in gh_deps_info.packages:
if package["public_dependents_number"] <= 0:
continue
assert os.path.isfile(csv_directory + os.path.sep + f"dependents_{package['name'].replace('/','-')}.csv")