ctsit / rcc.billing

Automated, data-driven service billing implemented on REDCap Custodian
https://ctsit.github.io/rcc.billing/
Apache License 2.0
0 stars 3 forks source link

Move test data 1 #251

Closed pbchase closed 2 months ago

pbchase commented 2 months ago

@saipavan10-git, I started a project last night to move test functions and test data into the ./tests/testthat/ space. The commits in this PR are the first of many. I'll admit I might merge this and release it because I want to see the documentation changes reflected in the public documentation website. Yet I want you to see what I am doing. It's a multi-pronged effort to reduce the scope of what is documented so you and others are not distracted by test code and test data. The changes come in a few forms:

Testing helpers

I moved several testing helper functions from R/devtools.R to tests/testthat/helper-package-specific.R. Files that match the pattern tests/testthat/helper*.R are executed before running tests. It makes the functions available to tests and only tests.

Moving the functions makes their man pages disappear from ./man/

Moving test data

We generated a lot of test data with code in ./data-raw/, writing the test data to ./data/, and documenting it with Roxygen2 code in ./R/data.R. All that was the wrong approach. To fix that, I am making these changes:

Replacing SQLite3 with DuckDB

In older tests, we use in-memory SQLite3 databases to house test data when tests need to run a function that connects to a DB. This was a poor choice because the SQLite3 data types are so limited. The lack of a proper datetime format is a big issue. In modern tests, we use a DuckDB in-memory database for its richer datatype support. In these commits, I am replacing SQLite use with Duck DB.

Streamlined table creation

In the older tests, we would create a table from a schema file, then populate the table from a test dataset. In newer tests, we create and populate tables in one step by reading a dataframe of test data, then calling with DBI::dbWriteTable() with the data frame as the value option to DBI::dbWriteTable()

Stop testing Schema files

We have a few tests of schema files to verify they load correctly. They are hacky, nearly useless, and a pain to rework for DuckDB. I am deleting these tests.

Other stuff

I have had to make a few small tweaks to functions and tests that broke with DuckDB, but they are few in number and small in size.

pbchase commented 2 months ago

The commits in this PR are the first of many. I'll admit I might merge this and release it because I want to see the documentation changes reflected in the public documentation website.

I am resisting the urge to merge and deploy this. Feel free to review it and understand it.

saipavan10-git commented 2 months ago

I started reviewing the PR and will merge it as soon as I'm done.