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

Code before:
            'ints_1d': int_expected_1d,
        }

        self.check_terms(
            terms,
            expected,
            initial_workspace={
                Floats(): floats,
                Dates(): dates,
                Strs(): self.make_labelarray(strs),
                Ints(): ints,

                AltFloats(): float_fillval,
                AltDates(): date_fillval,
                AltStrs(): self.make_labelarray(str_fillval),
                AltInts(): int_fillval,
            },
            mask=mask,
        )

    def should_error(self, f, exc_type, expected_message):
        with self.assertRaises(exc_type) as e:
            f()

        message = str(e.exception)
        assert expected_message in message

    def test_bad_inputs(self):
        def dtype_for(o):
            return np.array([o]).dtype

        self.should_error(
            lambda: Floats().fillna('3.0'),
            TypeError,
            " from {!r} to {!r} according to the rule 'same_kind'"
            .format(dtype_for('3.0'), np.dtype(float))
        )

        self.should_error(
            lambda: Dates().fillna('2014-01-02'),
            TypeError,
            "from {!r} to {!r} according to the rule 'same_kind'"
            .format(dtype_for('2014-01-02'), np.dtype('M8[ns]'))
        )

        self.should_error(
            lambda: Ints().fillna('300'),
            TypeError,
            "from {!r} to {!r} according to the rule 'same_kind'"
            .format(dtype_for('300'), np.dtype('i8')),
        )

Review comment (suggestion):
Since we're using nose here (which doesn't rewrite `asserts` like pytest does), how about:
```suggestion
        self.assertIn(expected_message, message)
```

Code after:
            'ints_1d': int_expected_1d,
        }

        self.check_terms(
            terms,
            expected,
            initial_workspace={
                Floats(): floats,
                Dates(): dates,
                Strs(): self.make_labelarray(strs),
                Ints(): ints,

                AltFloats(): float_fillval,
                AltDates(): date_fillval,
                AltStrs(): self.make_labelarray(str_fillval),
                AltInts(): int_fillval,
            },
            mask=mask,
        )

    def should_error(self, f, exc_type, expected_message):
        with self.assertRaises(exc_type) as e:
            f()

        message = str(e.exception)
        self.assertIn(expected_message, message)

    def test_bad_inputs(self):
        def dtype_for(o):
            return np.array([o]).dtype

        self.should_error(
            lambda: Floats().fillna('3.0'),
            TypeError,
            " from {!r} to {!r} according to the rule 'same_kind'"
            .format(dtype_for('3.0'), np.dtype(float))
        )

        self.should_error(
            lambda: Dates().fillna('2014-01-02'),
            TypeError,
            "from {!r} to {!r} according to the rule 'same_kind'"
            .format(dtype_for('2014-01-02'), np.dtype('M8[ns]'))
        )

        self.should_error(
            lambda: Ints().fillna('300'),
            TypeError,
            "from {!r} to {!r} according to the rule 'same_kind'"
            .format(dtype_for('300'), np.dtype('i8')),
        )