Skip to content

Commit 9237668

Browse files
switch to third edition for testing
1 parent 17b764b commit 9237668

File tree

4 files changed

+80
-51
lines changed

4 files changed

+80
-51
lines changed

R/exec.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ path_precommit_exec <- function(check_if_exists = TRUE) {
3232
final
3333
}
3434

35+
#' Get the operating System
36+
#'
37+
#' Can't mock base package (either because it's an `.Internal` or for some other
38+
#' reason).
39+
#' @keywords internal
40+
get_os <- function() {
41+
tolower(Sys.info()[["sysname"]])
42+
}
43+
3544
#' @rdname path_precommit_exec
3645
#' @examples
3746
#' \dontrun{
@@ -56,7 +65,7 @@ path_pre_commit_exec <- function(check_if_exists = TRUE) {
5665
#' @keywords internal
5766
path_derive_precommit_exec <- function() {
5867
path <- path_derive_precommit_exec_path()
59-
os <- tolower(Sys.info()[["sysname"]])
68+
os <- get_os()
6069
if (os == "darwin") {
6170
path <- c(path, path_derive_precommit_exec_macOS())
6271
} else if (os == "windows") {

man/get_os.Rd

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-conda.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ if (!on_cran()) {
181181
})
182182
test_that("can update via conda", {
183183
if (not_conda()) {
184+
local_mocked_bindings(assert_reticulate_is_installed = function(...) NULL)
184185
expect_error(
185-
with_mock(update_precommit(), "precommit:::assert_reticulate_is_installed" = function(...) NULL),
186+
update_precommit(),
186187
paste(
187188
"You can only update your pre-commit executable via the R API if you",
188189
"chose the installation method via conda"

tests/testthat/test-exec.R

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
test_that("Path can be derived for windows Python >= 3.0", {
2-
paths_base <- with_mock(
3-
"precommit::path_derive_precommit_exec_win_python3plus_candidates" = function() {
1+
test_that("Path can be derived for windows Python >= 3.0 (mocked)", {
2+
local_mocked_bindings(
3+
path_derive_precommit_exec_win_python3plus_candidates = function() {
44
c(
55
fs::path_home("AppData/Roaming/Python/Python35"),
66
fs::path_home("AppData/Roaming/Python/Python37")
77
)
8-
},
9-
path_derive_precommit_exec_win_python3plus_base()
8+
}
109
)
1110

1211
expect_equal(
13-
paths_base,
12+
path_derive_precommit_exec_win_python3plus_base(),
1413
c(
1514
fs::path(fs::path_home(), "AppData/Roaming/Python/Python37/Scripts"),
1615
fs::path(fs::path_home(), "AppData/Roaming/Python/Python35/Scripts")
17-
)
16+
),
17+
ignore_attr = TRUE
1818
)
19+
})
20+
21+
22+
test_that("Path can be derived for windows Python >= 3.0 (actual)", {
1923
skip_if(!is_windows())
2024
skip_if(!not_conda())
2125
skip_if(on_cran())
@@ -28,61 +32,63 @@ test_that("Path can be derived for windows Python >= 3.0", {
2832

2933

3034
test_that("Warns when there are multiple installations found (2x os)", {
35+
local_mocked_bindings(
36+
path_derive_precommit_exec_path = function(candidate) {
37+
fs::path_home("AppData/Roaming/Python/Python35")
38+
},
39+
get_os = function(...) {
40+
c(sysname = "windows")
41+
},
42+
path_derive_precommit_exec_win = function() {
43+
c(
44+
fs::path_home("AppData/Roaming/Python/Python34"),
45+
fs::path_home("AppData/Roaming/Python/Python37")
46+
)
47+
}
48+
)
49+
3150
expect_warning(
32-
with_mock(
33-
"precommit::path_derive_precommit_exec_path" = function(candidate) {
34-
fs::path_home("AppData/Roaming/Python/Python35")
35-
},
36-
"Sys.info" = function(...) {
37-
c(sysname = "windows")
38-
},
39-
"precommit:::path_derive_precommit_exec_win" = function() {
40-
c(
41-
fs::path_home("AppData/Roaming/Python/Python34"),
42-
fs::path_home("AppData/Roaming/Python/Python37")
43-
)
44-
},
45-
path_derive_precommit_exec()
46-
),
51+
path_derive_precommit_exec(),
4752
"We detected multiple pre-commit executables"
4853
)
4954
})
5055

5156
test_that("Warns when there are multiple installations found (2x path)", {
57+
local_mocked_bindings(
58+
path_derive_precommit_exec_path = function(candidate) {
59+
c(
60+
fs::path_home("AppData/Roaming/Python/Python35"),
61+
fs::path_home("AppData/Roaming/Python/Python37")
62+
)
63+
},
64+
get_os = function(...) {
65+
c(sysname = "windows")
66+
},
67+
path_derive_precommit_exec_win = function() {
68+
fs::path_home("AppData/Roaming/Python/Python34")
69+
}
70+
)
5271
expect_warning(
53-
with_mock(
54-
"precommit::path_derive_precommit_exec_path" = function(candidate) {
55-
c(
56-
fs::path_home("AppData/Roaming/Python/Python35"),
57-
fs::path_home("AppData/Roaming/Python/Python37")
58-
)
59-
},
60-
"Sys.info" = function(...) {
61-
c(sysname = "windows")
62-
},
63-
"precommit:::path_derive_precommit_exec_win" = function() {
64-
fs::path_home("AppData/Roaming/Python/Python34")
65-
},
66-
path_derive_precommit_exec()
67-
),
72+
path_derive_precommit_exec(),
6873
"We detected multiple pre-commit executables"
6974
)
7075
})
7176

7277
test_that("Warns when there are multiple installations found (path and os)", {
78+
local_mocked_bindings(
79+
path_derive_precommit_exec_path = function(candidate) {
80+
fs::path_home("AppData/Roaming/Python/Python35")
81+
},
82+
path_derive_precommit_exec_win = function() {
83+
fs::path_home("AppData/Roaming/Python/Python34")
84+
},
85+
get_os = function(...) {
86+
c(sysname = "windows")
87+
},
88+
)
89+
7390
expect_warning(
74-
with_mock(
75-
"precommit::path_derive_precommit_exec_path" = function(candidate) {
76-
fs::path_home("AppData/Roaming/Python/Python35")
77-
},
78-
"Sys.info" = function(...) {
79-
c(sysname = "windows")
80-
},
81-
"precommit:::path_derive_precommit_exec_win" = function() {
82-
fs::path_home("AppData/Roaming/Python/Python34")
83-
},
84-
path_derive_precommit_exec()
85-
),
91+
path_derive_precommit_exec(),
8692
"We detected multiple pre-commit executables"
8793
)
8894
})

0 commit comments

Comments
 (0)