本文整理匯總了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"}},
}
)
示例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
示例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)
示例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))
示例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')
示例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")
示例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)
示例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')
示例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")
示例10: testInvalidType
def testInvalidType(self):
with self.assertRaises(BadSpecError):
TransformFactory.get_transform({"type": "not_a_transform_type", "custom_type": "user_display"})
示例11: get_format_fn
def get_format_fn(self):
if self.transform:
return TransformFactory.get_transform(self.transform).get_transform_function()
return None
示例12: test_missing_translation
def test_missing_translation(self):
transform = TransformFactory.get_transform({"type": "translation", "translations": {}}).get_transform_function()
self.assertEqual(transform("foo"), "foo")
示例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)
示例14: testValidCustom
def testValidCustom(self):
transform = TransformFactory.get_transform({"type": "custom", "custom_type": "user_display"})
self.assertTrue(isinstance(transform, CustomTransform))
示例15: testInvalidCustomType
def testInvalidCustomType(self):
with self.assertRaises(BadSpecError):
TransformFactory.get_transform({"type": "custom", "custom_type": "not_valid"})