ibllib.tests.base

Module attributes

INTEGRATION_DATA_WRITABLE

When False (INTEGRATION_DATA_WRITABLE=0), IntegrationTest.setUpClass creates a writable symlink mirror of required_files under a TemporaryDirectory so tests can write output files without touching the read-only data mount (e.g. S3).

Functions

disable_log

Decorator to temporarily disable the log.

list_current_sessions

Get the set of session eids used in integration tests.

make_sym_links

This creates symlinks to a scratch directory to start an extraction while leaving the raw data untouched.

Classes

IntegrationTest

Base class for tests that require S3 integration data.

TimeLoggingTestResult

A class to record test durations

TimeLoggingTestRunner

A class that prints a list of the slowest tests to the output stream

INTEGRATION_DATA_WRITABLE = True

When False (INTEGRATION_DATA_WRITABLE=0), IntegrationTest.setUpClass creates a writable symlink mirror of required_files under a TemporaryDirectory so tests can write output files without touching the read-only data mount (e.g. S3).

class TimeLoggingTestResult(*args, **kwargs)[source]

Bases: TextTestResult

A class to record test durations

startTest(test)[source]

Called when the given test is about to be run

addSuccess(test)[source]

Called when a test has completed successfully

getTestDurations() list[tuple[str, int]][source]

Returns list of tests and their durations, in reverse duration order

class TimeLoggingTestRunner(slow_test_threshold=0.3, *args, **kwargs)[source]

Bases: TextTestRunner

A class that prints a list of the slowest tests to the output stream

run(test)[source]

Run the given test case or test suite.

class IntegrationTest(*args, **kwargs)[source]

Bases: TestCase

Base class for tests that require S3 integration data.

Subclass this for any test needing integration data. When INTEGRATION_DATA_DIR is unset or missing (e.g. an outside contributor running plain python -m unittest discover), these tests auto-skip, so the unit suite still runs cleanly.

required_files = []

An optional list of required files/folders to glob for, relative to data_path.

data_path = PosixPath('.')

Active data root. Resolves to the writable temp dir when active, else the configured root. Works on both classes (cls.data_path in setUpClass) and instances (self.data_path in tests). Subclasses may narrow it: self.data_path = self.data_path / subdir.

classmethod setUpClass()[source]

Hook method for setting up class fixture before running tests in the class.

classmethod tearDownClass()[source]

Hook method for deconstructing the class fixture after running all tests in the class.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

classmethod default_data_root()[source]

Returns the configured data root (class-level temp dir if active, else INTEGRATION_DATA_DIR).

For instance-level path resolution (e.g. in setUp or test methods), use self.data_path instead — it also checks for instance-level temp dirs created by _writable_scope=’test’.

backup_alf(session_path)[source]

Backup alf folder.

Some extraction tests backup the ALF folder, extract the data into a new alf folder then compare the results. This function moves the original ALF folder to a backup location.

static restore_alf(session_path)[source]

Restore backup alf folder.

Some extraction tests backup the ALF folder, extract the data into a new alf folder then compare the results. This function moves the backed up folder back.

list_current_sessions(one=None)[source]

Get the set of session eids used in integration tests. When writing new tests, this can be a useful way of choosing which sessions to use.

Parameters:

one – An ONE object for fetching session eid from path

Returns:

Set of integration session eids

disable_log(level=50, restore_level=None, quiet=False)[source]

Decorator to temporarily disable the log.

Parameters:
  • level – The minimum logging level to disable

  • restore_level – The logging level to restore

  • quiet – If false the fact that the log is disabled will be printed

Returns:

This creates symlinks to a scratch directory to start an extraction while leaving the raw data untouched.

Parameters:
  • source_path – location containing the extraction fixture

  • extraction_path – (None) scratch location where the symlinks will end up,

omitting the session parts example: “/tmp”. If set to None, it will create a temporary directory using tempdir. :param fallback_to_copy: (True) if the symlink fails, it will copy the file instead. :return: