@@ -13,20 +13,27 @@ test_data = c("obs_id: FJ712037.1 - name: Panthera leo - taxon_id: 9689 - class_
13
13
test_regex <- " obs_id: (.*) - name: (.*) - taxon_id: (.*) - class_name: (.*) - class_id: (.*)"
14
14
15
15
check_for_internet <- function () {
16
- if (! is.character(RCurl :: getURL(" www.google.com" ))) {
16
+ result <- tryCatch(RCurl :: getURL(" www.google.com" ), error = function (e ) FALSE )
17
+ if (! is.character(result )) {
17
18
skip(" Internet not available" )
18
19
}
19
20
}
20
21
22
+ print_on_error <- function (result ) {
23
+ paste0(c(" ---- RESULT ----" , capture.output(str(result ))), collapse = " \n " )
24
+ }
25
+
21
26
# |
22
27
# | ### Exracting by obs_id
23
28
test_that(" Exracting by obs_id works" , {
29
+ skip_on_cran()
24
30
check_for_internet()
25
31
result <- extract_taxonomy(test_data , key = " obs_id" , regex = " obs_id: (.*?) -" , database = " ncbi" )
26
32
expect_s3_class(result , " taxmap" )
27
- expect_true(" Eukaryota" %in% result $ taxon_data $ name )
33
+ expect_true(" Eukaryota" %in% result $ taxon_data $ name , info = print_on_error( result ) )
28
34
})
29
35
test_that(" Invalid IDs cause understandable errors" , {
36
+ skip_on_cran()
30
37
check_for_internet()
31
38
expect_error(extract_taxonomy(c(" FJ712037.1" , " notvalid" , " HW243304.1" ),
32
39
key = " obs_id" , regex = " (.*)" , database = " ncbi" ,
@@ -40,9 +47,10 @@ test_that("Exracting by classification names works", {
40
47
result <- extract_taxonomy(test_data , key = " class" , regex = " class_name: (.*?) -" ,
41
48
class_key = " name" , class_regex = " (.*)" , class_sep = " ;" )
42
49
expect_s3_class(result , " taxmap" )
43
- expect_true(" Caniformia" %in% result $ taxon_data $ name )
50
+ expect_true(" Caniformia" %in% result $ taxon_data $ name , info = print_on_error( result ) )
44
51
})
45
52
test_that(" Looking up IDs for classification names works" , {
53
+ skip_on_cran()
46
54
check_for_internet()
47
55
result <- extract_taxonomy(c(" Ascomycota_sp|AY773457|SH189849.06FU|reps|k__Fungi;p__Ascomycota;c__unidentified;o__unidentified;f__unidentified;g__unidentified;s__Ascomycota_sp" ,
48
56
" Myrmecridium_schulzeri|EU041774|SH189850.06FU|reps|k__Fungi;p__Ascomycota;c__Sordariomycetes;o__Incertae_sedis;f__Incertae_sedis;g__Myrmecridium;s__Myrmecridium_schulzeri" ,
@@ -55,7 +63,7 @@ test_that("Looking up IDs for classification names works", {
55
63
class_sep = " ;" ,
56
64
database = " ncbi" )
57
65
expect_s3_class(result , " taxmap" )
58
- expect_equal(result $ taxon_data $ ncbi_id [1 ], " 4751" )
66
+ expect_equal(result $ taxon_data $ ncbi_id [1 ], " 4751" , info = print_on_error( result ) )
59
67
})
60
68
61
69
@@ -67,25 +75,27 @@ test_that("Exracting by classification IDs works", {
67
75
result <- extract_taxonomy(test_data , key = " class" , regex = " class_id: (.*?)$" ,
68
76
class_key = " taxon_id" , class_regex = " (.*)" , class_sep = " ;" )
69
77
expect_s3_class(result , " taxmap" )
70
- expect_true(" 379583" %in% result $ taxon_data $ taxon_id )
78
+ expect_true(" 379583" %in% result $ taxon_data $ taxon_id , info = print_on_error( result ) )
71
79
})
72
80
73
81
# |
74
82
# | ### Exracting by taxon name
75
83
test_that(" Exracting by taxon name works" , {
84
+ skip_on_cran()
76
85
check_for_internet()
77
86
result <- extract_taxonomy(test_data , key = " name" , regex = " name: (.*?) - " , database = " ncbi" )
78
87
expect_s3_class(result , " taxmap" )
79
- expect_true(" 379583" %in% result $ taxon_data $ ncbi_id )
88
+ expect_true(" 379583" %in% result $ taxon_data $ ncbi_id , info = print_on_error( result ) )
80
89
})
81
90
82
91
# |
83
92
# | ### Exracting by taxon ID
84
93
test_that(" Exracting by taxon ID works" , {
94
+ skip_on_cran()
85
95
check_for_internet()
86
96
result <- extract_taxonomy(test_data , key = " taxon_id" , regex = " taxon_id: (.*?) - " , database = " ncbi" )
87
97
expect_s3_class(result , " taxmap" )
88
- expect_true(" Eukaryota" %in% result $ taxon_data $ name )
98
+ expect_true(" Eukaryota" %in% result $ taxon_data $ name , info = print_on_error( result ) )
89
99
})
90
100
91
101
# |
0 commit comments