def test_coerce_with_source_error_type_dict(self): with self.assertRaises(ValueError): coerce_I18nMessage(("my_id", { "hello": "there" }, { "library": "cjwmodule" }))
def test_coerce_from_dict(self): with self.assertRaises(ValueError): coerce_I18nMessage({ "id": "my_id", "arguments": { "hello": "there" } })
def test_coerce_with_source_library_none(self): self.assertEqual( coerce_I18nMessage(("my_id", { "hello": "there" }, None)), I18nMessage("my_id", {"hello": "there"}, None), )
def test_coerce_with_source_library(self): self.assertEqual( coerce_I18nMessage(("my_id", { "hello": "there" }, "cjwmodule")), I18nMessage("my_id", {"hello": "there"}, "cjwmodule"), )
def test_coerce_from_tuple(self): self.assertEqual( coerce_I18nMessage(("my_id", { "hello": "there" })), I18nMessage("my_id", {"hello": "there"}, None), )
def __render_arrow( *, table: types.ArrowTable, params: Dict[str, Any], tab_name: str, fetch_result: Optional[types.FetchResult], output_path: Path, ) -> types.RenderResult: """Render using `cjwkernel.types` data types. Write to `output_path`. This will typically call `render()`. """ # call render() raw_result = render( table.table, params, output_path, columns=table.metadata.columns, settings=settings, tab_name=tab_name, fetch_result=fetch_result, ) # coerce result # TODO let module output column types. (Currently, the lack of column types # means this is only useful for fetch modules that don't output number # formats.) table = types.ArrowTable.from_arrow_file_with_inferred_metadata( output_path, fallback_column_types={c.name: c.type for c in table.metadata.columns}, ) errors = [] # TODO support more output types? Or develop the One True Types (maybe # types.RenderResult) and force modules to output it. if isinstance(raw_result, list): # List of I18nMessage errors errors = [ # TODO don't use coerce_I18nMessage? At least, don't use ptypes. # Do any modules even require coerce? Or do they all correctly # output tuples-or-text? Is it only unit tests that output # non-I18nMessage tuples? types.RenderError(ptypes.coerce_I18nMessage(message)) for message in raw_result ] elif raw_result is None: errors = [] return types.RenderResult(table, errors)
def test_coerce_with_invalid_source(self): with self.assertRaises(ValueError): coerce_I18nMessage(("my_id", {"hello": "there"}, "random"))
def test_coerce_with_source_empty(self): with self.assertRaises(ValueError): coerce_I18nMessage(("my_id", {"hello": "there"}, {})),
def test_coerce_from_string(self): self.assertEqual( coerce_I18nMessage("some string"), I18nMessage("TODO_i18n", {"text": "some string"}, None), )