예제 #1
0
파일: auditor.py 프로젝트: rhlobo/bigtempo
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
예제 #2
0
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
예제 #3
0
 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)
예제 #4
0
    def test_slice_given_nothing(self):
        data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

        result = utils.slice(data)
        assert result == data
예제 #5
0
    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]
예제 #6
0
    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:]
예제 #7
0
 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
예제 #8
0
 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)
예제 #9
0
파일: auditor.py 프로젝트: rhlobo/bigtempo
 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