3
3
# Copyright (c) Balasankar C <balasankarc@autistici.org> and others
4
4
# SPDX-License-Identifier: GPL-3.0-or-later OR MIT
5
5
6
+ import json
7
+ import os
8
+
6
9
from gemfileparser2 import GemfileParser
7
10
11
+ TEST_DATA_DIR = os .path .join (os .path .dirname (__file__ ), 'data' )
12
+
8
13
9
14
def check_gemparser_results (test_file , regen = False ):
10
15
"""
11
- Run GemfileParser.parse on `test_file` and check against a JSON file that
12
- contains expected results with the same name as the `test_file` with a
16
+ Run GemfileParser.parse on `` test_file` ` and check against a JSON file that
17
+ contains expected results with the same name as the `` test_file` ` with a
13
18
"-expected.json" suffix appended.
14
19
"""
15
- import json
16
-
20
+ test_file = os .path .join (TEST_DATA_DIR , test_file )
17
21
gemparser = GemfileParser (test_file )
18
22
dependencies = {
19
- group : [dep .to_dict () for dep in deps ] for group , deps in gemparser .parse ().items ()
23
+ group : [dep .to_dict () for dep in deps ]
24
+ for group , deps in gemparser .parse ().items ()
20
25
}
21
26
22
- expected_file = test_file + " -expected.json"
27
+ expected_file = f" { test_file } -expected.json"
23
28
if regen :
24
29
with open (expected_file , "w" ) as o :
25
30
json .dump (dependencies , o , indent = 2 )
@@ -31,40 +36,40 @@ def check_gemparser_results(test_file, regen=False):
31
36
32
37
33
38
def test_source_only_gemfile ():
34
- check_gemparser_results ("tests /Gemfile" )
39
+ check_gemparser_results ("gemfiles /Gemfile" )
35
40
36
41
37
42
def test_gemfile_1 ():
38
- check_gemparser_results ("tests /Gemfile_1" )
43
+ check_gemparser_results ("gemfiles /Gemfile_1" )
39
44
40
45
41
46
def test_gemfile_2 ():
42
- check_gemparser_results ("tests /Gemfile_2" )
47
+ check_gemparser_results ("gemfiles /Gemfile_2" )
43
48
44
49
45
50
def test_gemfile_3 ():
46
- check_gemparser_results ("tests /Gemfile_3" )
51
+ check_gemparser_results ("gemfiles /Gemfile_3" )
47
52
48
53
49
54
def test_gemfile_4 ():
50
- check_gemparser_results ("tests /Gemfile_4" )
55
+ check_gemparser_results ("gemfiles /Gemfile_4" )
51
56
52
57
53
58
def test_gemfile_platforms ():
54
- check_gemparser_results ("tests /Gemfile_5" )
59
+ check_gemparser_results ("gemfiles /Gemfile_5" )
55
60
56
61
57
62
def test_gemspec_1 ():
58
- check_gemparser_results ("tests /sample.gemspec" )
63
+ check_gemparser_results ("gemspecs /sample.gemspec" )
59
64
60
65
61
66
def test_gemspec_2 ():
62
- check_gemparser_results ("tests /address_standardization.gemspec" )
67
+ check_gemparser_results ("gemspecs /address_standardization.gemspec" )
63
68
64
69
65
70
def test_gemspec_3 ():
66
- check_gemparser_results ("tests /arel.gemspec" )
71
+ check_gemparser_results ("gemspecs /arel.gemspec" )
67
72
68
73
69
74
def test_gemspec_4 ():
70
- check_gemparser_results ("tests /logstash-mixin-ecs_compatibility_support.gemspec" )
75
+ check_gemparser_results ("gemspecs /logstash-mixin-ecs_compatibility_support.gemspec" )
0 commit comments