Closed andreww closed 3 years ago
An example of how to deal with temporary directories:https://github.com/andreww/lema/blob/master/tests/hc_tests.py (But this uses unittest, maybe pytest does something similar?)
@andreww to look at context module in tests - how should this work?
additional to-do:
pathlib
instead of inspect
, os
etc. Instead of trying to figure out relative paths from inside modules (possibly different working directories? - check with some thoughtfully placed print(pathlib.Path.cwd())
statements), figure out file paths at start (in set up or testing, depending on use) and pass these in as strings into different functions and objects. This will simplify testing filepaths too - if filepaths are set up all together at the start, won't have the issues of duplicating the output_runs\
directory within both the tests\
and pytesimal\
directories.Also, the tempfile
module used in above example is independent of unittest
; looking at pytest
alternatives to setup and teardown methods - fixtures? Useful for testing (#32 ) and reusing data from time-consuming timestepping runs. Still need something like this before and after testing:
def setUp(self):
# Create a temporary directory for each test
self.test_dir = tempfile.mkdtemp()
self.starting_dir = os.getcwd()
os.chdir(self.test_dir)
def tearDown(self):
# Remove the directory after each test
os.chdir(self.starting_dir)
shutil.rmtree(self.test_dir)
Not sure outside of the unittest
TestCase
framework how to force the order of these - eg if tests are in a variety of test_something.py
files, how can you get the setup function to run before anything, and the teardown function to run afterwards - even if something fails? Todo - look this up. I guess alternative is just to have these in each module with tests - maybe this is best practise as it allows tests to be run independently.
Actual packaging probably needs to be in an issue by itself. But for the record documentation is at https://packaging.python.org/
File restructuring done, migrating to packaging issue https://github.com/murphyqm/pytesimal/issues/39
This issue can collect together the various bits and bobs that need thinking about to turn the current repository into something that is a python package. We can link to more detailed issues as needed. Anyway, I there are the following basic tasks:
pytesimal.conductive_cooling
orpytesimal.modular_cond_cooling.conductive_cooling
. This will need a new file (called__init__.py
) in the pytesimal directory. This turns the directory into a python package. The file is often empty, but anything in that file can be accessed by doingimport pytesimal
. What is quite common is to import the most commonly used functions into that file. Probably worth thinking about what we want the externally facing API to look like.I've probably forgotten something else too.