@@ -13,20 +13,27 @@ test_data = c("obs_id: FJ712037.1 - name: Panthera leo - taxon_id: 9689 - class_
1313test_regex <- " obs_id: (.*) - name: (.*) - taxon_id: (.*) - class_name: (.*) - class_id: (.*)"
1414
1515check_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 )) {
1718 skip(" Internet not available" )
1819 }
1920}
2021
22+ print_on_error <- function (result ) {
23+ paste0(c(" ---- RESULT ----" , capture.output(str(result ))), collapse = " \n " )
24+ }
25+
2126# |
2227# | ### Exracting by obs_id
2328test_that(" Exracting by obs_id works" , {
29+ skip_on_cran()
2430 check_for_internet()
2531 result <- extract_taxonomy(test_data , key = " obs_id" , regex = " obs_id: (.*?) -" , database = " ncbi" )
2632 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 ) )
2834})
2935test_that(" Invalid IDs cause understandable errors" , {
36+ skip_on_cran()
3037 check_for_internet()
3138 expect_error(extract_taxonomy(c(" FJ712037.1" , " notvalid" , " HW243304.1" ),
3239 key = " obs_id" , regex = " (.*)" , database = " ncbi" ,
@@ -40,9 +47,10 @@ test_that("Exracting by classification names works", {
4047 result <- extract_taxonomy(test_data , key = " class" , regex = " class_name: (.*?) -" ,
4148 class_key = " name" , class_regex = " (.*)" , class_sep = " ;" )
4249 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 ) )
4451})
4552test_that(" Looking up IDs for classification names works" , {
53+ skip_on_cran()
4654 check_for_internet()
4755 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" ,
4856 " 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", {
5563 class_sep = " ;" ,
5664 database = " ncbi" )
5765 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 ) )
5967})
6068
6169
@@ -67,25 +75,27 @@ test_that("Exracting by classification IDs works", {
6775 result <- extract_taxonomy(test_data , key = " class" , regex = " class_id: (.*?)$" ,
6876 class_key = " taxon_id" , class_regex = " (.*)" , class_sep = " ;" )
6977 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 ) )
7179})
7280
7381# |
7482# | ### Exracting by taxon name
7583test_that(" Exracting by taxon name works" , {
84+ skip_on_cran()
7685 check_for_internet()
7786 result <- extract_taxonomy(test_data , key = " name" , regex = " name: (.*?) - " , database = " ncbi" )
7887 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 ) )
8089})
8190
8291# |
8392# | ### Exracting by taxon ID
8493test_that(" Exracting by taxon ID works" , {
94+ skip_on_cran()
8595 check_for_internet()
8696 result <- extract_taxonomy(test_data , key = " taxon_id" , regex = " taxon_id: (.*?) - " , database = " ncbi" )
8797 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 ) )
8999})
90100
91101# |
0 commit comments