|
16 | 16 | from testing.language_helpers import run_language |
17 | 17 |
|
18 | 18 |
|
19 | | -@pytest.fixture |
20 | | -def renv_lock_file(tmp_path): |
21 | | - renv_lock = '''\ |
22 | | -{ |
23 | | -"R": { |
24 | | - "Version": "4.0.3", |
25 | | - "Repositories": [ |
26 | | - { |
27 | | - "Name": "CRAN", |
28 | | - "URL": "https://cloud.r-project.org" |
29 | | - } |
30 | | - ] |
31 | | -}, |
32 | | -"Packages": { |
33 | | - "renv": { |
34 | | - "Package": "renv", |
35 | | - "Version": "0.12.5", |
36 | | - "Source": "Repository", |
37 | | - "Repository": "CRAN", |
38 | | - "Hash": "5c0cdb37f063c58cdab3c7e9fbb8bd2c" |
39 | | - }, |
40 | | - "rprojroot": { |
41 | | - "Package": "rprojroot", |
42 | | - "Version": "1.0", |
43 | | - "Source": "Repository", |
44 | | - "Repository": "CRAN", |
45 | | - "Hash": "86704667fe0860e4fec35afdfec137f3" |
46 | | - } |
47 | | -} |
48 | | -} |
49 | | - ''' |
50 | | - tmp_path.joinpath('renv.lock').write_text(renv_lock) |
51 | | - yield |
52 | | - |
53 | | - |
54 | | -@pytest.fixture |
55 | | -def description_file(tmp_path): |
56 | | - description = '''\ |
57 | | -Package: gli.clu |
58 | | -Title: What the Package Does (One Line, Title Case) |
59 | | -Type: Package |
60 | | -Version: 0.0.0.9000 |
61 | | -Authors@R: |
62 | | - person(given = "First", |
63 | | - family = "Last", |
64 | | - role = c("aut", "cre"), |
65 | | - |
66 | | - comment = c(ORCID = "YOUR-ORCID-ID")) |
67 | | -Description: What the package does (one paragraph). |
68 | | -License: `use_mit_license()`, `use_gpl3_license()` or friends to |
69 | | - pick a license |
70 | | -Encoding: UTF-8 |
71 | | -LazyData: true |
72 | | -Roxygen: list(markdown = TRUE) |
73 | | -RoxygenNote: 7.1.1 |
74 | | -Imports: |
75 | | - rprojroot |
76 | | - ''' |
77 | | - tmp_path.joinpath('DESCRIPTION').write_text(description) |
78 | | - yield |
79 | | - |
80 | | - |
81 | | -@pytest.fixture |
82 | | -def hello_world_file(tmp_path): |
83 | | - hello_world = '''\ |
84 | | -stopifnot( |
85 | | - packageVersion('rprojroot') == '1.0', |
86 | | - packageVersion('gli.clu') == '0.0.0.9000' |
87 | | -) |
88 | | -cat("Hello, World, from R!\n") |
89 | | -''' |
90 | | - tmp_path.joinpath('hello-world.R').write_text(hello_world) |
91 | | - yield |
92 | | - |
93 | | - |
94 | | -@pytest.fixture |
95 | | -def renv_folder(tmp_path): |
96 | | - |
97 | | - renv_dir = tmp_path.joinpath('renv') |
98 | | - renv_dir.mkdir() |
99 | | - shutil.copy( |
100 | | - os.path.join( |
101 | | - os.path.dirname(__file__), |
102 | | - '../../pre_commit/resources/empty_template_activate.R', |
103 | | - ), |
104 | | - renv_dir.joinpath('activate.R'), |
105 | | - ) |
106 | | - yield |
107 | | - |
108 | | - |
109 | 19 | def test_r_parsing_file_no_opts_no_args(tmp_path): |
110 | 20 | cmd = r._cmd_from_hook( |
111 | 21 | Prefix(str(tmp_path)), |
@@ -220,6 +130,96 @@ def test_path_rscript_exec_no_r_home_set(): |
220 | 130 | assert r._rscript_exec() == 'Rscript' |
221 | 131 |
|
222 | 132 |
|
| 133 | +@pytest.fixture |
| 134 | +def renv_lock_file(tmp_path): |
| 135 | + renv_lock = '''\ |
| 136 | +{ |
| 137 | +"R": { |
| 138 | + "Version": "4.0.3", |
| 139 | + "Repositories": [ |
| 140 | + { |
| 141 | + "Name": "CRAN", |
| 142 | + "URL": "https://cloud.r-project.org" |
| 143 | + } |
| 144 | + ] |
| 145 | +}, |
| 146 | +"Packages": { |
| 147 | + "renv": { |
| 148 | + "Package": "renv", |
| 149 | + "Version": "0.12.5", |
| 150 | + "Source": "Repository", |
| 151 | + "Repository": "CRAN", |
| 152 | + "Hash": "5c0cdb37f063c58cdab3c7e9fbb8bd2c" |
| 153 | + }, |
| 154 | + "rprojroot": { |
| 155 | + "Package": "rprojroot", |
| 156 | + "Version": "1.0", |
| 157 | + "Source": "Repository", |
| 158 | + "Repository": "CRAN", |
| 159 | + "Hash": "86704667fe0860e4fec35afdfec137f3" |
| 160 | + } |
| 161 | +} |
| 162 | +} |
| 163 | + ''' |
| 164 | + tmp_path.joinpath('renv.lock').write_text(renv_lock) |
| 165 | + yield |
| 166 | + |
| 167 | + |
| 168 | +@pytest.fixture |
| 169 | +def description_file(tmp_path): |
| 170 | + description = '''\ |
| 171 | +Package: gli.clu |
| 172 | +Title: What the Package Does (One Line, Title Case) |
| 173 | +Type: Package |
| 174 | +Version: 0.0.0.9000 |
| 175 | +Authors@R: |
| 176 | + person(given = "First", |
| 177 | + family = "Last", |
| 178 | + role = c("aut", "cre"), |
| 179 | + |
| 180 | + comment = c(ORCID = "YOUR-ORCID-ID")) |
| 181 | +Description: What the package does (one paragraph). |
| 182 | +License: `use_mit_license()`, `use_gpl3_license()` or friends to |
| 183 | + pick a license |
| 184 | +Encoding: UTF-8 |
| 185 | +LazyData: true |
| 186 | +Roxygen: list(markdown = TRUE) |
| 187 | +RoxygenNote: 7.1.1 |
| 188 | +Imports: |
| 189 | + rprojroot |
| 190 | + ''' |
| 191 | + tmp_path.joinpath('DESCRIPTION').write_text(description) |
| 192 | + yield |
| 193 | + |
| 194 | + |
| 195 | +@pytest.fixture |
| 196 | +def hello_world_file(tmp_path): |
| 197 | + hello_world = '''\ |
| 198 | +stopifnot( |
| 199 | + packageVersion('rprojroot') == '1.0', |
| 200 | + packageVersion('gli.clu') == '0.0.0.9000' |
| 201 | +) |
| 202 | +cat("Hello, World, from R!\n") |
| 203 | +''' |
| 204 | + tmp_path.joinpath('hello-world.R').write_text(hello_world) |
| 205 | + yield |
| 206 | + |
| 207 | + |
| 208 | +@pytest.fixture |
| 209 | +def renv_folder(tmp_path): |
| 210 | + |
| 211 | + renv_dir = tmp_path.joinpath('renv') |
| 212 | + renv_dir.mkdir() |
| 213 | + shutil.copy( |
| 214 | + os.path.join( |
| 215 | + os.path.dirname(__file__), |
| 216 | + '../../pre_commit/resources/empty_template_activate.R', |
| 217 | + ), |
| 218 | + renv_dir.joinpath('activate.R'), |
| 219 | + ) |
| 220 | + yield |
| 221 | + |
| 222 | + |
223 | 223 | def test_r_hook( |
224 | 224 | tmp_path, |
225 | 225 | renv_lock_file, |
|
0 commit comments