Repository: quantopian/zipline
File: tests/pipeline/test_domain.py (Python)

Code before:
from zipline.pipeline.domain import (
    AmbiguousDomain,
    BE_EQUITIES,
    CA_EQUITIES,
    CH_EQUITIES,
    DE_EQUITIES,
    FR_EQUITIES,
    GB_EQUITIES,
    GENERIC,
    infer_domain,
    JP_EQUITIES,
    NL_EQUITIES,
    PT_EQUITIES,
    US_EQUITIES,
    EquityCalendarDomain,
    EquitySessionDomain,
)
from zipline.pipeline.factors import CustomFactor
import zipline.testing.fixtures as zf
from zipline.testing.core import parameter_space, powerset
from zipline.testing.predicates import assert_equal, assert_messages_equal
from zipline.utils.pandas_utils import days_at_time


DOMAINS = [
    BE_EQUITIES,
    CA_EQUITIES,
    CH_EQUITIES,
    DE_EQUITIES,
    FR_EQUITIES,
    GB_EQUITIES,
    JP_EQUITIES,
    NL_EQUITIES,
    PT_EQUITIES,
    US_EQUITIES,
]


class Sum(CustomFactor):

    def compute(self, today, assets, out, data):
        out[:] = data.sum(axis=0)

    @classmethod
    def create(cls, column, window_length):
        return cls(inputs=[column], window_length=window_length)


class MixedGenericsTestCase(zf.WithSeededRandomPipelineEngine,
                            zf.ZiplineTestCase):
    START_DATE = pd.Timestamp('2014-01-02', tz='utc')

Review comment (bug):
Probably the most important thing for us to test for each new domain is that its calendar code resolves as expected. The test for the EquityCalendarDomain defaults at https://github.com/quantopian/zipline/pull/2301/files#diff-8dd6ea1d2db90f77c7c793ecc4704888R339 do a good job of exercising that functionality, but right now that requires someone adding a new domain to remember to add it to the list in that test. One way to make it more likely that that happens would be to move this list to `domain.py` and rename it to something like `BUILT_IN_DOMAINS`. Then in this test, we could define the expected cutoff time for each domain and assert we have a definition for each builtin, so that if a user adds a domain and doesn't update the test, we'd fail.

Code after:
from zipline.pipeline.domain import (
    AmbiguousDomain,
    BUILT_IN_DOMAINS,
    BE_EQUITIES,
    CA_EQUITIES,
    CH_EQUITIES,
    DE_EQUITIES,
    FR_EQUITIES,
    GB_EQUITIES,
    GENERIC,
    infer_domain,
    JP_EQUITIES,
    NL_EQUITIES,
    PT_EQUITIES,
    US_EQUITIES,
    EquityCalendarDomain,
    EquitySessionDomain,
)
from zipline.pipeline.factors import CustomFactor
import zipline.testing.fixtures as zf
from zipline.testing.core import parameter_space, powerset
from zipline.testing.predicates import assert_equal, assert_messages_equal
from zipline.utils.pandas_utils import days_at_time


class Sum(CustomFactor):

    def compute(self, today, assets, out, data):
        out[:] = data.sum(axis=0)

    @classmethod
    def create(cls, column, window_length):
        return cls(inputs=[column], window_length=window_length)


class MixedGenericsTestCase(zf.WithSeededRandomPipelineEngine,
                            zf.ZiplineTestCase):
    START_DATE = pd.Timestamp('2014-01-02', tz='utc')
    END_DATE = pd.Timestamp('2014-01-31', tz='utc')
    ASSET_FINDER_EQUITY_SIDS = (1, 2, 3, 4, 5)
    ASSET_FINDER_COUNTRY_CODE = 'US'

    def test_mixed_generics(self):
        """
        Test that we can run pipelines with mixed generic/non-generic terms.

        This test is a regression test for failures encountered during
        development where having a mix of generic and non-generic columns in
        the term graph caused bugs in our extra row accounting.
        """
        USTestingDataSet = TestingDataSet.specialize(US_EQUITIES)