potc.testing.trans¶
transobj_assert¶
-
potc.testing.trans.
transobj_assert
(obj: object, trans=None)[source]¶ - Overview:
Assertion-based test for
potc.translate.quick.transobj()
function.This function is managed by
contextmanager
, so you can use it with awith
block.- Arguments:
obj (
object
): Object to be translatedtrans: Translator to be used. See
potc.translate.quick.transobj()
.
- Examples::
>>> with transobj_assert([1, -2, 3.2, '1234']) as obj, name: ... assert obj == [1, -2, 3.2, '1234'] ... assert name == 'builtin_list'
Note
When this function is called, the translated object code will be dumped into a python file and then import from it, so please make sure the code you created can be supported by standard python grammar.
transvars_assert¶
-
potc.testing.trans.
transvars_assert
(vars_: Mapping[str, Any], trans=None, reformat=None, isort: bool = True)[source]¶ - Overview:
Assertion-based test for
potc.translate.quick.transvars()
function.This function is managed by
contextmanager
, so you can use it with awith
block.- Arguments:
- vars_ (
Mapping[str, Any]
): The items to be translated, should be a mapping contains all the values and their names.
- vars_ (
trans: Translator to be used. See
potc.translate.quick.transvars()
.reformat: Reformatter to be used. See
potc.translate.quick.transvars()
.isort (
bool
): Sort the import statements. Seepotc.translate.quick.transvars()
.
- Examples::
>>> with transvars_assert({ ... 'a': 233, ... 'b': [1, 2, 3, {'x': 1}], ... }) as (v, code): ... assert v == { # v is the mapping of the values ... 'a': 233, ... 'b': [1, 2, 3, {'x': 1}], ... } ... assert 'import' not in code # code is the dumped source code
Note
When this function is called, the translated object code will be dumped into a python file and then import from it, so please make sure the code you created can be supported by standard python grammar.