Skip to content

Test generation failure when dataset contains non-ascii chars #51

@alanfranz

Description

@alanfranz

Consider

https://github.com/alanfranz/pyjomap/tree/ecb4572851b0b1939eab747ac37edebd26c49524

and precisely the test case:

https://github.com/alanfranz/pyjomap/blob/ecb4572851b0b1939eab747ac37edebd26c49524/pyjomap/test/test_mapping.py#L45

I just refactored the tests to use genty_dataset. When running the tests (just run make test in project directory. Using python 2.7 and genty 1.3.2. ) I get the following error:

======================================================================
ERROR: pyjomap.test.test_mapping (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: pyjomap.test.test_mapping
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 254, in _find_tests
    module = self._get_module_from_name(name)
  File "/opt/homebrew/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name
    __import__(name)
  File "/Users/alan/sources/pyjomap/pyjomap/test/test_mapping.py", line 45, in <module>
    class TestMappingFromDict(TestCase):
  File "/Users/alan/sources/pyjomap/pyjomap/test/test_mapping.py", line 58, in TestMappingFromDict
    MyItem("5", u"whatààà", [{"1": "2"}, {"1": "2"}], {1: "1", 2: "2"}, e=Other("5", "6"))),
  File "/Users/alan/sources/pyjomap/devenv/lib/python2.7/site-packages/genty/genty_dataset.py", line 137, in genty_dataset
    datasets = _build_datasets(*args, **kwargs)
  File "/Users/alan/sources/pyjomap/devenv/lib/python2.7/site-packages/genty/genty_dataset.py", line 169, in _build_datasets
    _add_arg_datasets(datasets, args)
  File "/Users/alan/sources/pyjomap/devenv/lib/python2.7/site-packages/genty/genty_dataset.py", line 195, in _add_arg_datasets
    dataset_strings = [format_arg(data) for data in dataset]
  File "/Users/alan/sources/pyjomap/devenv/lib/python2.7/site-packages/genty/private/__init__.py", line 32, in format_arg
    return translator(value)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128)

All the encodings are properly set in source files; my impression is that genty tries to read the dataset to generate test method names, but makes assumptions on the content of bytestrings; I think it should just skip such data, if it's not able to interpret it.

As a workaround I'm now using the pre-named tests, but I think it's a bug that should be solved whatsoever.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions