File tree Expand file tree Collapse file tree 2 files changed +97
-0
lines changed
Expand file tree Collapse file tree 2 files changed +97
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Main Tests
2+
3+ on :
4+ push :
5+ branches : [ "master" ]
6+ pull_request :
7+ branches : [ "master" ]
8+
9+ jobs :
10+ test-commits :
11+ runs-on : ubuntu-latest
12+ steps :
13+ - uses : actions/checkout@v4
14+
15+ - name : Set up Python
16+ uses : actions/setup-python@v5
17+ with :
18+ python-version : ' 3.11'
19+
20+ - name : Install dependencies
21+ run : |
22+ python -m pip install --upgrade pip
23+ pip install -r requirements.txt
24+
25+ - name : Run main.py and save output (commits)
26+ run : |
27+ python main.py --repo isaacs/github --commits -o output_commits.csv
28+
29+ - name : Compare output with reference CSV (commits)
30+ run : |
31+ python compare_csv.py output_commits.csv .github/workflows/reference_commits.csv
32+
33+ - name : Run main.py and save output (contributors)
34+ run : |
35+ python main.py --repo isaacs/github --contributors -o output_contributors.csv
36+
37+ - name : Compare output with reference CSV (contributors)
38+ run : |
39+ python compare_csv.py output_contributors.csv .github/workflows/reference_contributors.csv
40+
41+ - name : Run main.py and save output (issues)
42+ run : |
43+ python main.py --repo isaacs/github --issues -o output_issues.csv
44+
45+ - name : Compare output with reference CSV (issues)
46+ run : |
47+ python compare_csv.py output_issues.csv .github/workflows/reference_issues.csv
48+
49+ - name : Run main.py and save output (pulls)
50+ run : |
51+ python main.py --repo isaacs/github --pulls -o output_pulls.csv
52+
53+ - name : Compare output with reference CSV (pulls)
54+ run : |
55+ python compare_csv.py output_pulls.csv .github/workflows/reference_pulls.csv
56+
Original file line number Diff line number Diff line change 1+ import csv
2+ import sys
3+
4+ def compare_csv_files (actual_path , expected_path ):
5+ with open (actual_path , newline = '' , encoding = 'utf-8' ) as actual_file , \
6+ open (expected_path , newline = '' , encoding = 'utf-8' ) as expected_file :
7+ actual_reader = csv .DictReader (actual_file )
8+ expected_reader = csv .DictReader (expected_file )
9+
10+ actual_rows = list (actual_reader )
11+ expected_rows = list (expected_reader )
12+
13+ common_fields = set (actual_reader .fieldnames ) & set (expected_reader .fieldnames )
14+ if not common_fields :
15+ print ('Нет общих столбцов для сравнения!' )
16+ sys .exit (1 )
17+
18+ def rows_to_set (rows ):
19+ return set (tuple (row [field ] for field in sorted (common_fields )) for row in rows )
20+
21+ actual_set = rows_to_set (actual_rows )
22+ expected_set = rows_to_set (expected_rows )
23+
24+ if actual_set != expected_set :
25+ print ('Файлы отличаются по общим столбцам:' )
26+ print ('Только в output.csv:' )
27+ for row in actual_set - expected_set :
28+ print (row )
29+ print ('Только в reference.csv:' )
30+ for row in expected_set - actual_set :
31+ print (row )
32+ sys .exit (1 )
33+ else :
34+ print ('Файлы совпадают по общим столбцам.' )
35+
36+ if __name__ == "__main__" :
37+ if len (sys .argv ) != 3 :
38+ print (f"Usage: python { sys .argv [0 ]} <actual_csv> <expected_csv>" )
39+ sys .exit (1 )
40+ compare_csv_files (sys .argv [1 ], sys .argv [2 ])
41+
You can’t perform that action at this time.
0 commit comments