def test_mapper_default_args(self) -> None: split_words = SplitWordsMapperDefaultArgs("split_words") split_words_spark = make_spark_mapper(split_words) x_mapped = split_words_spark(self._get_x()) assert x_mapped is not None self.assertEqual(x_mapped.num, 8) self.assertEqual(x_mapped.text, "Henry has fun") self.assertEqual(x_mapped.lower, "henry has fun") self.assertEqual(x_mapped.words, ["Henry", "has", "fun"])
def test_mapper_same_field(self) -> None: split_words = SplitWordsMapper("split_words", "text", "text", "text_words") split_words_spark = make_spark_mapper(split_words) x = self._get_x() x_mapped = split_words_spark(x) self.assertEqual(x.num, 8) self.assertEqual(x.text, "Henry has fun") self.assertFalse(hasattr(x, "text_words")) assert x_mapped is not None self.assertEqual(x_mapped.num, 8) self.assertEqual(x_mapped.text, "henry has fun") self.assertEqual(x_mapped.text_words, ["Henry", "has", "fun"])
def test_mapper_returns_none(self) -> None: mapper = MapperReturnsNone("none_mapper") mapper_spark = make_spark_mapper(mapper) x_mapped = mapper_spark(self._get_x()) self.assertIsNone(x_mapped)