当前位置: 首页>>代码示例>>Python>>正文


Python factory.TransformFactory类代码示例

本文整理汇总了Python中corehq.apps.userreports.transforms.factory.TransformFactory的典型用法代码示例。如果您正苦于以下问题:Python TransformFactory类的具体用法?Python TransformFactory怎么用?Python TransformFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TransformFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_bad_option

 def test_bad_option(self):
     with self.assertRaises(BadSpecError):
         TransformFactory.get_transform(
             {
                 "type": "translation",
                 "mobile_or_web": "neither!",
                 "translations": {"0": "zero", "1": {"en": "one", "es": "uno"}, "2": {"en": "two", "es": "dos"}},
             }
         )
开发者ID:dimagi,项目名称:commcare-hq,代码行数:9,代码来源:test_transforms.py

示例2: get_format_fn

 def get_format_fn(self):
     """
     A function that gets applied to the data just in time before the report is rendered.
     """
     if self.transform:
         return TransformFactory.get_transform(self.transform).get_transform_function()
     return None
开发者ID:sheelio,项目名称:commcare-hq,代码行数:7,代码来源:specs.py

示例3: test_string_transform

 def test_string_transform(self):
     transform = TransformFactory.get_transform({
         "type": "custom",
         "custom_type": "days_elapsed_from_date"
     })
     date = (datetime.utcnow() - timedelta(days=5)).strftime('%Y-%m-%d')
     self.assertEqual(transform.transform(date), 5)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:7,代码来源:test_transforms.py

示例4: test_gregorian_to_ethiopian

def test_gregorian_to_ethiopian(self, date_string, expected_result):
    transform = TransformFactory.get_transform({
        "type": "custom",
        "custom_type": "gregorian_date_to_ethiopian_date",
    }).get_transform_function()

    self.assertEqual(expected_result, transform(date_string))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:7,代码来源:test_transforms.py

示例5: test_basic_translation

 def test_basic_translation(self):
     transform = TransformFactory.get_transform({
         "type": "translation",
         "translations": {
             "#0000FF": "Blue"
         },
     }).get_transform_function()
     self.assertEqual(transform('#0000FF'), 'Blue')
     self.assertEqual(transform('#123456'), '#123456')
开发者ID:dimagi,项目名称:commcare-hq,代码行数:9,代码来源:test_transforms.py

示例6: test_spanish_language_translation

 def test_spanish_language_translation(self):
     transform = TransformFactory.get_transform(
         {
             "type": "translation",
             "translations": {"#0000FF": {"en": "Blue", "es": "Azul"}, "#800080": {"en": "Purple", "es": "Morado"}},
         }
     ).get_transform_function()
     self.assertEqual(transform("#0000FF"), "Azul")
     self.assertEqual(transform("#800080"), "Morado")
     self.assertEqual(transform("#123456"), "#123456")
开发者ID:dimagi,项目名称:commcare-hq,代码行数:10,代码来源:test_transforms.py

示例7: parsed_expression

 def parsed_expression(self, context):
     from corehq.apps.userreports.expressions.factory import ExpressionFactory
     expression = ExpressionFactory.from_spec(self.expression, context)
     datatype_transform = transform_from_datatype(self.datatype)
     if self.transform:
         generic_transform = TransformFactory.get_transform(self.transform).get_transform_function()
         inner_getter = TransformedGetter(expression, generic_transform)
     else:
         inner_getter = expression
     return TransformedGetter(inner_getter, datatype_transform)
开发者ID:nnestle,项目名称:commcare-hq,代码行数:10,代码来源:specs.py

示例8: test_dont_translate_for_mobile

 def test_dont_translate_for_mobile(self):
     transform = TransformFactory.get_transform({
         "type": "translation",
         "mobile_or_web": "mobile",
         "translations": {
             "#0000FF": "Blue",
             "#800080": [["en", "Purple"], ["es", "Morado"]],  # legacy, mobile-only format
         },
     }).get_transform_function()
     self.assertEqual(transform('#0000FF'), '#0000FF')
     self.assertEqual(transform('#800080'), '#800080')
     self.assertEqual(transform('#123456'), '#123456')
开发者ID:dimagi,项目名称:commcare-hq,代码行数:12,代码来源:test_transforms.py

示例9: test_multi_translation

 def test_multi_translation(self):
     transform = TransformFactory.get_transform({
         "type": "multiple_value_string_translation",
         "translations": {
             "#0000FF": "Blue",
             "#800080": "Purple"
         },
         "delimiter": " "
     }).get_transform_function()
     self.assertEqual(transform('#0000FF #800080'), 'Blue Purple')
     self.assertEqual(transform('#800080 #123456'), 'Purple #123456')
     self.assertEqual(transform('#123 #123456'), '#123 #123456')
     self.assertEqual(transform("#0000FF"), "Blue")
开发者ID:dimagi,项目名称:commcare-hq,代码行数:13,代码来源:test_transforms.py

示例10: testInvalidType

 def testInvalidType(self):
     with self.assertRaises(BadSpecError):
         TransformFactory.get_transform({"type": "not_a_transform_type", "custom_type": "user_display"})
开发者ID:dimagi,项目名称:commcare-hq,代码行数:3,代码来源:test_transforms.py

示例11: get_format_fn

 def get_format_fn(self):
     if self.transform:
         return TransformFactory.get_transform(self.transform).get_transform_function()
     return None
开发者ID:jmaina,项目名称:commcare-hq,代码行数:4,代码来源:specs.py

示例12: test_missing_translation

 def test_missing_translation(self):
     transform = TransformFactory.get_transform({"type": "translation", "translations": {}}).get_transform_function()
     self.assertEqual(transform("foo"), "foo")
开发者ID:dimagi,项目名称:commcare-hq,代码行数:3,代码来源:test_transforms.py

示例13: test_datetime_transform

 def test_datetime_transform(self):
     transform = TransformFactory.get_transform({"type": "custom", "custom_type": "days_elapsed_from_date"})
     self.assertEqual(transform.transform(datetime.utcnow() - timedelta(days=5)), 5)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:3,代码来源:test_transforms.py

示例14: testValidCustom

 def testValidCustom(self):
     transform = TransformFactory.get_transform({"type": "custom", "custom_type": "user_display"})
     self.assertTrue(isinstance(transform, CustomTransform))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:3,代码来源:test_transforms.py

示例15: testInvalidCustomType

 def testInvalidCustomType(self):
     with self.assertRaises(BadSpecError):
         TransformFactory.get_transform({"type": "custom", "custom_type": "not_valid"})
开发者ID:dimagi,项目名称:commcare-hq,代码行数:3,代码来源:test_transforms.py


注:本文中的corehq.apps.userreports.transforms.factory.TransformFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。