nestorsalceda / mamba

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

When executing the mamba in non-utf-8 environment would cause exception #118

Open cmtony opened 6 years ago

cmtony commented 6 years ago

https://github.com/nestorsalceda/mamba/blob/8ec25de42171403a3ecf3db4c162053af058f6d7/mamba/example_collector.py#L81 As title, when I executed the mamba in non-utf-8 environment, it would cause exception like:

Traceback (most recent call last):
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36-32\Scripts\mamba.exe\__main__.py", line 9, in <module>
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mamba\cli.py", line 18, in main
    runner.run()
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mamba\runners.py", line 29, in run
    modules = self.example_collector.modules()
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mamba\example_collector.py", line 25, in modules
    with self._load_module_from(path) as module:
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36-32\lib\contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mamba\example_collector.py", line 57, in _load_module_from
    yield self._module_from_ast(name, path)
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mamba\example_collector.py", line 60, in _module_from_ast
    tree = self._parse_and_transform_ast(path)
  File "C:\Users\tony\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mamba\example_collector.py", line 82, in _parse_and_transform_ast
    tree = ast.parse(f.read(), filename=path)

UnicodeDecodeError: 'cp950' codec can't decode byte 0xe6 in position 1602: illegal multibyte sequence

To solve this issue, I've tried to update this line(mamba/mamba/example_collector.py, line 81) as below and it works:

    with open(path, encoding='utf-8') as f:

Could anyone please update the encoding to 'utf-8' in this file?