def _assert_datasource_correctness_using_datafiles(engine, reference, symbol, start, end, test_data_filepath_fn): logger = utils.DatasourceLogger() original_registrations = {} for dependency_reference in engine._registrations[reference]['dependencies']: mock_data_file = test_data_filepath_fn(dependency_reference, symbol) if not os.path.isfile(mock_data_file): continue datasource_mock_cls = _create_mock_datasource(dependency_reference, mock_data_file, logger) if not engine._registrations.get(dependency_reference): engine._registrations[dependency_reference] = {} original_registrations[dependency_reference] = engine._registrations[dependency_reference] registration_mock = copy.deepcopy(engine._registrations[dependency_reference]) registration_mock['class'] = datasource_mock_cls registration_mock['dependencies'] = set() engine._registrations[dependency_reference] = registration_mock expected_data_file = test_data_filepath_fn(reference, symbol) actual = engine.get(reference).process(symbol, start, end) expected = utils.slice(pandas.DataFrame.from_csv(expected_data_file), start, end) logger.log('actual', actual) logger.log('expected', expected) try: _assert_dataframe_almost_equal(expected, actual) except Exception, e: logger.print_summary() raise e
def _assert_datasource_correctness_using_datafiles(engine, reference, symbol, start, end, test_data_filepath_fn): logger = utils.DatasourceLogger() original_registrations = {} for dependency_reference in engine._registrations[reference][ 'dependencies']: mock_data_file = test_data_filepath_fn(dependency_reference, symbol) if not os.path.isfile(mock_data_file): continue datasource_mock_cls = _create_mock_datasource(dependency_reference, mock_data_file, logger) if not engine._registrations.get(dependency_reference): engine._registrations[dependency_reference] = {} original_registrations[dependency_reference] = engine._registrations[ dependency_reference] registration_mock = copy.deepcopy( engine._registrations[dependency_reference]) registration_mock['class'] = datasource_mock_cls registration_mock['dependencies'] = set() engine._registrations[dependency_reference] = registration_mock expected_data_file = test_data_filepath_fn(reference, symbol) actual = engine.get(reference).process(symbol, start, end) expected = utils.slice(pandas.DataFrame.from_csv(expected_data_file), start, end) logger.log('actual', actual) logger.log('expected', expected) try: _assert_dataframe_almost_equal(expected, actual) except Exception, e: logger.print_summary() raise e
def process(self, symbol, start=None, end=None): context = self._create_context_for(symbol, start, end) result = self._instance.evaluate(context, symbol, start, end) return utils.slice(result, start, end)
def test_slice_given_nothing(self): data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] result = utils.slice(data) assert result == data
def test_slice_given_end(self): data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] result = utils.slice(data, end=8) assert result == data[:8]
def test_slice_given_start(self): data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] result = utils.slice(data, 2) assert result == data[2:]
def evaluate(self, context, symbol, start=None, end=None): data = pandas.DataFrame.from_csv(mock_data_file) sliced_data = utils.slice(data, start, end) logger.log(os.path.basename(mock_data_file), sliced_data) return sliced_data