當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。