diff options
Diffstat (limited to 'tests/testthat')
| -rw-r--r-- | tests/testthat/_snaps/chent.md | 18 | ||||
| -rw-r--r-- | tests/testthat/test_chent.R | 31 | ||||
| -rw-r--r-- | tests/testthat/test_pai.R | 30 |
3 files changed, 44 insertions, 35 deletions
diff --git a/tests/testthat/_snaps/chent.md b/tests/testthat/_snaps/chent.md new file mode 100644 index 0000000..b214852 --- /dev/null +++ b/tests/testthat/_snaps/chent.md @@ -0,0 +1,18 @@ +# We can initialise an object and add information + + Code + print(oct) + Output + <chent> + Identifier $identifier 1-octanol + InChI Key $inchikey KBPLFHHGFOOTCA-UHFFFAOYSA-N + SMILES string $smiles: + user PubChem + "CCCCCCCCO" "CCCCCCCCO" + Molecular weight $mw: 130.2 + PubChem synonyms (up to 10): + [1] "1-octanol" "Octan-1-ol" "111-87-5" + [4] "N-octanol" "Octyl alcohol" "caprylic alcohol" + [7] "n-Octyl alcohol" "Heptyl carbinol" "1-Hydroxyoctane" + [10] "Primary octyl alcohol" + diff --git a/tests/testthat/test_chent.R b/tests/testthat/test_chent.R index 4551cf7..1f4a186 100644 --- a/tests/testthat/test_chent.R +++ b/tests/testthat/test_chent.R @@ -1,24 +1,21 @@ -context("Generation of chent objects") - # Check if we can use RDKit skip_if_no_rdkit <- function() { if (!chents:::rdkit_available) skip("RDKit is not available via reticulate") } -oct <- chent$new("1-octanol", smiles = "CCCCCCCCO", pubchem = FALSE, chyaml = FALSE) - -test_that("We can generate a chent object from SMILES using RDKit", { +test_that("We can initialise an object and add information", { + oct <- chent$new("1-octanol", smiles = "CCCCCCCCO", rdkit = FALSE, pubchem = FALSE, chyaml = FALSE) + expect_equal(oct$identifier, c(X1.octanol = "1-octanol")) # The name of the identifier is generated using make.names() + expect_equal(oct$inchikey, structure(NA, source = "user")) + expect_equal(oct$smiles, c(user = "CCCCCCCCO")) + oct$try_pubchem() |> + expect_message("Querying PubChem for name 1-octanol") |> + expect_warning("Overwriting uninitialized InChIKey") + expect_equal(oct$inchikey, structure("KBPLFHHGFOOTCA-UHFFFAOYSA-N", source = "pubchem")) + expect_equal(oct$smiles[["PubChem"]], "CCCCCCCCO") skip_if_no_rdkit() - expect_equivalent(round(oct$mw, 2), 130.23) - expect_equal(names(oct$identifier), "X1.octanol") - expect_equal(oct$smiles[["user"]], "CCCCCCCCO") -}) - -test_that("We can add information retrieved from PubChem via webchem", { - oct$try_pubchem() - expect_equivalent(round(oct$mw, 2), 130.23) - ik = "KBPLFHHGFOOTCA-UHFFFAOYSA-N" - attr(ik, "source") <- "pubchem" - expect_equal(oct$inchikey, ik) - expect_equal(oct$smiles[["PubChem_Canonical"]], "CCCCCCCCO") + oct$get_rdkit() |> + expect_message("Get chemical information from RDKit using user SMILES") + expect_equal(round(oct$mw, 2), structure(130.23, source = "pubchem")) + expect_snapshot(print(oct)) }) diff --git a/tests/testthat/test_pai.R b/tests/testthat/test_pai.R index 518fc56..0d5264a 100644 --- a/tests/testthat/test_pai.R +++ b/tests/testthat/test_pai.R @@ -1,22 +1,16 @@ -# For manual use of this file -require(chents) -require(testthat) - -context("Generation of pai objects") - -test_that("a pai object is correctly generated from an ambiguous name", { +test_that("a pai object is correctly generated", { skip_on_travis() # server certificate verification failed in curl_fetch_memory() - glyphosate <- pai$new("glyphosate", chyaml = FALSE) - expect_message(pai$new("benzalkonium chloride", chyaml = FALSE), "did not give results") - - expect_equivalent(glyphosate$bcpc$cas, "1071-83-6") - expect_equivalent(glyphosate$bcpc$formula, "C3H8NO5P") - expect_equivalent(glyphosate$bcpc$iupac_name, "N-(phosphonomethyl)glycine") + {glyphosate <- pai$new("glyphosate")} |> + expect_message("Querying BCPC for glyphosate") |> + expect_message("Querying PubChem for inchikey ") |> + expect_message("Get chemical information from RDKit using PubChem SMILES") + + expect_equal(glyphosate$bcpc$cas, "1071-83-6") + expect_equal(glyphosate$bcpc$formula, "C3H8NO5P") + expect_equal(glyphosate$bcpc$iupac_name, "N-(phosphonomethyl)glycine") expect_equal(names(glyphosate$identifier), "glyphosate") ik = "XDDAORKBJWWYJS-UHFFFAOYSA-N" - attr(ik, "source") <- c("bcpc", "pubchem") - expect_equal(glyphosate$inchikey, ik) - expect_equivalent(round(glyphosate$mw, 2), 169.07) - smiles <- "C(C(=O)O)NCP(=O)(O)O" - expect_equal(glyphosate$smiles[["PubChem_Canonical"]], smiles) + expect_equal(glyphosate$inchikey, structure("XDDAORKBJWWYJS-UHFFFAOYSA-N", source = c("bcpc", "pubchem"))) + expect_equal(round(glyphosate$mw, 2), structure(169.07, source = "pubchem")) + expect_equal(glyphosate$smiles[["PubChem"]], "C(C(=O)O)NCP(=O)(O)O") }) |
