Cobaya: unit tests of code using cobaya
Posted: September 22 2020
Hi Antony and Jesus, I wanted to ask about how to set up unit testing of code that uses Cobaya. It seems that unit testing any code that calls cobaya has the following challenges:
1) Using pytest at least, any code that calls cobaya gets stopped at these lines in cobaya/log.py, in the function `logger_setup`
If these lines are commented out, the test would run fine. However that doesn't seem like a great solution in the long run, for I'm sure the lines are doing something useful. Would you please let me know what your proposed solution would be?
2) When I write a new theory or likelihood class, I can only write a unit test for functionalities that do not need things like `state` and `**params_values_dict`, which depends on other theory modules and how cobaya initializes the sampled parameters. So as a result I cannot test separately ingredients of `calculate` function. Is there anyway to generate a sample `state`, `params_values_dict` and `provider` within cobaya to do the unit test for a theory module? Or would there be pre-written test classes for Theory and Likelihood that users can inherit? Please let us know what's the best way of doing this! Thank you!
1) Using pytest at least, any code that calls cobaya gets stopped at these lines in cobaya/log.py, in the function `logger_setup`
Code: Select all
if not any(h.stream == sys.stdout for h in logging.root.handlers):
logging.root.addHandler(handle_stdout)
2) When I write a new theory or likelihood class, I can only write a unit test for functionalities that do not need things like `state` and `**params_values_dict`, which depends on other theory modules and how cobaya initializes the sampled parameters. So as a result I cannot test separately ingredients of `calculate` function. Is there anyway to generate a sample `state`, `params_values_dict` and `provider` within cobaya to do the unit test for a theory module? Or would there be pre-written test classes for Theory and Likelihood that users can inherit? Please let us know what's the best way of doing this! Thank you!