autowisp.tests package

Class Inheritance Diagram

Inheritance diagram of AutoWISPTestCase, FloatTestCase, Interpreter, Sequence, TemporaryDirectory

Autowisp unit-test init.

class autowisp.tests.AutoWISPTestCase(methodName='runTest')[source]

Bases: FloatTestCase

Inheritance diagram of autowisp.tests.AutoWISPTestCase

Base class for AutoWISP tests.

_compare_headers(fname1, fname2, header1, header2)[source]

Assert that the two FITS headers match.

Parameters:
  • fname1 (str) – Names of the files (for messages).

  • fname2 (str) – Names of the files (for messages).

  • header1 – The astropy.io.fits.Header objects.

  • header2 – The astropy.io.fits.Header objects.

_point_at_test_database()[source]

Send this test’s project database to the configured server.

Nothing else in the suite – and no pipeline or step code – needs to know. set_project_home already reads autowisp_db.url from the project home when it is there, and every step launched by run_step() runs with that directory as its cwd, so it resolves the same file. Writing it here therefore redirects the whole run, subprocesses included.

A no-op when the variable is unset, which is the default.

_test_failed()[source]

Whether this test has just failed or errored.

Read off the result rather than a flag the test sets, so nothing has to be remembered at the end of every test method. Two things make the obvious shortcuts wrong: _outcome.success is still True here (it is reset per test part, and tearDown is its own part), and result.errors / result.failures accumulate over the whole run – so the entries have to be matched against this test rather than merely counted.

Returns:

True if this test recorded a failure or an error.

Return type:

bool

get_inputs(inputs)[source]

Get the input files for the test step and return what to clean up.

preserve_failed_processing = True

Set False by a test that does not want its processing directory kept even when it fails (nothing does at present). Failure is detected from the test result, so a passing test never has to say anything – the previous arrangement, where each test opted in by setting successful_test, silently preserved the directory of every test that forgot to.

preserve_processing_dir = None
run_step(command)[source]

Run a calibration step and check the return code.

setUp()[source]

Make sure the data to compare against is defined.

classmethod set_test_directory(test_dirname, processing_dirname, failed_test_dirname, preserve_processing_dir=None)[source]

Set the directory where data to test against is located.

stage_catalog_cache = True
tearDown()[source]

Remove the processing directory.

autowisp.tests.SERVER_URL_ENV = 'AUTOWISP_TEST_DB_URL'

Environment variable naming a MySQL/MariaDB URL to test against.

Unset – the default, and what a developer gets locally – puts every project database in a throwaway SQLite file, as before. Setting it runs the same tests against a centralised server, which is a supported deployment but one the suite has never exercised: SQLite compares strings case-sensitively, does not enforce foreign keys or column widths, and serialises writers instead of taking row locks.

autowisp.tests._redirected_user_data_dir(*args, **kwargs)[source]

Return the throwaway directory whatever application is asked for.

autowisp.tests._user_data_dir = <TemporaryDirectory '/var/folders/hm/n65vjtk55fg79mcg2sz1g6280000gp/T/autowisp_tests_qzkwxdyl'>

Throwaway stand-in for the real user data directory.

Five call sites derive paths from platformdirs.user_data_dir("autowisp"): the BUI database and bui.log (django_project/settings.py), the default project home when none is given (database/interface.py), and the run_pipeline.out capture file (run_pipeline.py and processing/views.py). Redirecting the lookup once, here, means no test can reach the developer’s real data by forgetting to override something – the BUI database in particular holds their project list.

This belongs in the package __init__ rather than __main__ because CI also runs modules directly (python -m unittest autowisp.tests.…), which never loads __main__. Importing anything under autowisp.tests executes this first, which matters because settings.py resolves the directory at import time.

autowisp.tests.empty_server_database(url)[source]

Drop every table in url, including alembic_version.

SQLite gets a fresh file per test simply by using a fresh directory. A server has one database shared by the whole run, so it has to be emptied between tests instead – and completely, since a leftover alembic_version would make the next project look migrated when its tables are gone.

autowisp.tests.server_test_url()[source]

Return the server URL to test against, or None for SQLite.

Empty counts as unset. A CI matrix that carries the URL as a per-cell key gives every other cell the variable set to an empty string rather than absent, and those cells must stay on SQLite.

Submodules