nestorsalceda / mamba

The definitive testing tool for Python. Born under the banner of Behavior Driven Development (BDD).
http://nestorsalceda.github.io/mamba
MIT License
520 stars 64 forks source link

Unicode support problems (for spec files and in some situations for modules under test) #133

Open Stvad opened 5 years ago

Stvad commented 5 years ago

Mamba seems to be trying to read the spec files decoding them using ascii decoder leading to problems when spec file contain any unicode character.

Minimal example to reproduce:

from mamba import description, it

with description("Spec"):
    with it("Should not fail 🤔"):
        pass

This is going to lead to the following error when trying to run it:

Traceback (most recent call last):
  File "/Users/sitalov/Dropbox/SoftwareEngineering/Projects/Anki/CrowdAnki/test/mamba_runner.py", line 3, in <module>
    main()
  File "/Users/sitalov/.local/share/virtualenvs/CrowdAnki-uIF4Vw2q/lib/python3.6/site-packages/mamba/cli.py", line 18, in main
    runner.run()
  File "/Users/sitalov/.local/share/virtualenvs/CrowdAnki-uIF4Vw2q/lib/python3.6/site-packages/mamba/runners.py", line 29, in run
    modules = self.example_collector.modules()
  File "/Users/sitalov/.local/share/virtualenvs/CrowdAnki-uIF4Vw2q/lib/python3.6/site-packages/mamba/example_collector.py", line 25, in modules
    with self._load_module_from(path) as module:
  File "/Users/sitalov/.pyenv/versions/3.6.8/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/Users/sitalov/.local/share/virtualenvs/CrowdAnki-uIF4Vw2q/lib/python3.6/site-packages/mamba/example_collector.py", line 57, in _load_module_from
    yield self._module_from_ast(name, path)
  File "/Users/sitalov/.local/share/virtualenvs/CrowdAnki-uIF4Vw2q/lib/python3.6/site-packages/mamba/example_collector.py", line 60, in _module_from_ast
    tree = self._parse_and_transform_ast(path)
  File "/Users/sitalov/.local/share/virtualenvs/CrowdAnki-uIF4Vw2q/lib/python3.6/site-packages/mamba/example_collector.py", line 82, in _parse_and_transform_ast
    tree = ast.parse(f.read(), filename=path)
  File "/Users/sitalov/.local/share/virtualenvs/CrowdAnki-uIF4Vw2q/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 90: ordinal not in range(128)