Source code for nilmtk.tests.testingtools

Tools to help with testing.

from __future__ import print_function, division
import os, inspect, warnings

[docs]def data_dir(): # Taken from current_file_path = os.path.dirname(inspect.getfile(inspect.currentframe())) data_dir = os.path.join(current_file_path, '..', '..', 'data') data_dir = os.path.abspath(data_dir) assert os.path.isdir(data_dir), data_dir + " does not exist." return data_dir
[docs]class WarningTestMixin(object): """A test which checks if the specified warning was raised. Taken from """
[docs] def assertWarns(self, warning, callable, *args, **kwds): with warnings.catch_warnings(record=True) as warning_list: warnings.simplefilter('always') result = callable(*args, **kwds) self.assertTrue(any(item.category == warning for item in warning_list), msg="Warning '{}' not raised.".format(warning))