'Test that `RollingPearsonOfReturns`, `RollingSpearmanOfReturns` and
`RollingLinearRegressionOfReturns` raise the proper exception when
given a nonexistent target asset.'

def test_correlation_and_regression_with_bad_asset(self):

    my_asset = Equity(0, exchange='TEST')
    start_date = self.pipeline_start_date
    end_date = self.pipeline_end_date
    run_pipeline = self.run_pipeline
    my_asset_filter = AssetID().eq(1)
    for mask in (NotSpecified, my_asset_filter):
        pearson_factor = RollingPearsonOfReturns(target=my_asset, returns_length=3, correlation_length=3, mask=mask)
        spearman_factor = RollingSpearmanOfReturns(target=my_asset, returns_length=3, correlation_length=3, mask=mask)
        regression_factor = RollingLinearRegressionOfReturns(target=my_asset, returns_length=3, regression_length=3, mask=mask)
        with self.assertRaises(NonExistentAssetInTimeFrame):
            run_pipeline(Pipeline(columns={'pearson_factor': pearson_factor}), start_date, end_date)
        with self.assertRaises(NonExistentAssetInTimeFrame):
            run_pipeline(Pipeline(columns={'spearman_factor': spearman_factor}), start_date, end_date)
        with self.assertRaises(NonExistentAssetInTimeFrame):
            run_pipeline(Pipeline(columns={'regression_factor': regression_factor}), start_date, end_date)
