diff options
| author | Ranke Johannes <johannes.ranke@agroscope.admin.ch> | 2025-10-22 16:27:37 +0200 | 
|---|---|---|
| committer | Ranke Johannes <johannes.ranke@agroscope.admin.ch> | 2025-10-22 16:27:37 +0200 | 
| commit | 7c0e06c053303ea3f35fad3236ee5b3d930e7f08 (patch) | |
| tree | 2843596590b70d2e892a3f325b0af04cb54c8387 /tests/testthat | |
| parent | b9a839f29beb9c10f22ace4b0dd4eee167ae6836 (diff) | |
Diffstat (limited to 'tests/testthat')
| -rw-r--r-- | tests/testthat/_snaps/chent.md | 18 | ||||
| -rw-r--r-- | tests/testthat/test_chent.R | 30 | ||||
| -rw-r--r-- | tests/testthat/test_pai.R | 29 | 
3 files changed, 39 insertions, 38 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 4546423..1f4a186 100644 --- a/tests/testthat/test_chent.R +++ b/tests/testthat/test_chent.R @@ -1,29 +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", rdkit = FALSE, pubchem = FALSE, chyaml = FALSE) - -test_that("We can initialise an object only with identifier and SMILES code", { +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")) -}) - -test_that("We can generate a chent object from SMILES using RDKit", { -  skip_if_no_rdkit() -  oct$get_rdkit() -  expect_equivalent(round(oct$mw, 2), 130.23) -}) - -test_that("We can add information retrieved from PubChem via webchem", { -  expect_warning(oct$try_pubchem(), "Overwriting uninitialized InChIKey") -  expect_equivalent(round(oct$mw, 2), 130.23) -  ik = "KBPLFHHGFOOTCA-UHFFFAOYSA-N" -  attr(ik, "source") <- "pubchem" -  expect_equal(oct$inchikey, ik) +  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() +  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 f38672d..0d5264a 100644 --- a/tests/testthat/test_pai.R +++ b/tests/testthat/test_pai.R @@ -1,25 +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", {    skip_on_travis() # server certificate verification failed in curl_fetch_memory() -  glyphosate <- pai$new("glyphosate") +  {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") -  # This did not give results at BCPC in previous times, so it was used to test -  # the corresponding warning. -  #bc <- pai$new("benzalkonium chloride")  - -  expect_equivalent(glyphosate$bcpc$cas, "1071-83-6") -  expect_equivalent(glyphosate$bcpc$formula, "C3H8NO5P") -  expect_equivalent(glyphosate$bcpc$iupac_name, "N-(phosphonomethyl)glycine") +  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"]], 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")  })  | 
