Bioconductor / BSgenomeForge

Tools to forge BSgenome data packages
4 stars 3 forks source link

Add unit tests for BSgenomeForge:::.get_circ_seqs() #17

Closed hpages closed 1 year ago

hpages commented 1 year ago

We're going to use the testthat framework to implement the unit tests for BSgenomeForge:::.get_circ_seqs().

testthat is a CRAN package that makes it easy to write and run unit tests. It's used by many Bioconductor packages. Note that some Bioconductor packages use RUnit for their unit tests, which is similar to testthat but has been around for much longer. Choosing between testthat, or RUnit, or any other testing framework, is the developer's choice.

Here are some examples of Bioconductor packages that use testthat: SingleCellExperiment, ensembldb, DESeq2, etc... All these packages contain a tests/testthat/ folder which is where their unit tests are implemented. Don't hesitate to take a look at what they've done.

The unit tests can be run interactively in various ways e.g. by starting R in the directory of the package that you want to test and calling devtools::test(), or with Cmd/Ctrl + Shift + T if you are in RStudio. See https://github.com/r-lib/testthat#readme Note that they will also be run by R CMD check.

BSgenomeForge is already set up to run its unit tests thru testthat, that is:

A good way to organize the tests in tests/testthat/ is to create one test_*.R file per function to test. So for the get_circ_seqs() function, let's put all the tests in tests/testthat/test_get_circ_seqs.R.

Let me know, or ask on Slack (our internal Slack or the community-bioc Slack), if you have any questions or need help with this.

H.

kakopo commented 1 year ago

Hi Hervé, please check my latest pull request regarding this issue and let me know what you think. Thank you!

hpages commented 1 year ago

Nice job with your first unit tests!

A few comments:

Thanks!

kakopo commented 1 year ago

Okay. Thank you for the feedback. Please have a look at the latest commit!

hpages commented 1 year ago

I merged PR #26 and made some minor edits to tests/testthat/test-get_circ_seqs.R. See commit f5af9971c36c2de98b793dba8e080a93e26ee25f. Please take a look and let me know if you have questions. Also don't forget to resync your fork.

Note that the reason I replaced regexp "registered[\\s]+in[\\s]+the[\\s]+GenomeInfoDb[\\s]+package" with "not[\\s]+registered" is that the former would also accept one of the error messages that start with "This assembly is registered in the GenomeInfoDb package ", and we don't want that (i.e. the test should fail if that's the case). The test should only succeed if the error message says that the assembly is NOT registered. Hope that makes sense.

Also it seems to me that the tests don't cover the case where the user supplies circular sequences that are valid sequence names but are not assembled molecules. This corresponds to this code (at the bottom of get_circ_seqs()):

    if (!all(circ_seqs %in% assembled_molecules))
        stop(wmsg("all the sequence names in 'circ_seqs' must be ",
                  "names of assembled molecules"))

Can you double check that? This would need to be covered too.

Please make the correction in a new PR if you need to add this test.

Let me know if you have questions.

Thanks!

kakopo commented 1 year ago

Note that the reason I replaced regexp "registered[\s]+in[\s]+the[\s]+GenomeInfoDb[\s]+package" with "not[\s]+registered" is that the former would also accept one of the error messages that start with "This assembly is registered in the GenomeInfoDb package ", and we don't want that (i.e. the test should fail if that's the case). The test should only succeed if the error message says that the assembly is NOT registered. Hope that makes sense.

This makes sense. Thank you. I've added the correction and created a new PR, please check it out, thanks.

hpages commented 1 year ago

Looks good. Please make sure that your code is properly indented. Thanks!

kakopo commented 1 year ago

Sorry about that! It should be properly indented now.

hpages commented 1 year ago

Thanks. I just merged PR #27 (please resync your fork).

Whenever you are ready, take a look at issue #25. As always, don't hesitate to ask if you need help.