Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add encoding to test results, update utils #1

Merged
merged 4 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: python
python:
- '2.7'
- '3.3'
- '3.4'
- '3.5-dev'
- '3.8'
- 'nightly'
matrix:
allow_failures:
Expand Down
2 changes: 1 addition & 1 deletion tmc/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ def addResult(self, test, status, err=None):
# TODO: Do not do this if not using TMCTestRunner
@atexit.register
def write_output():
with open('.tmc_test_results.json', 'w') as f:
with open('.tmc_test_results.json', 'w', encoding='utf8') as f:
json.dump(results, f, ensure_ascii=False)
29 changes: 27 additions & 2 deletions tmc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,34 @@
import sys


def load(pkg, method, err=None):
def load_module(pkg, lang='en'):
module_not_found = 'File {0} does not exist!'.format(pkg)
other_exception = 'Running exercise {0} failed. Please make sure that you can run your code.'.format(pkg)
if lang == 'fi':
module_not_found = 'Tiedostoa {0} ei löytynyt.'.format(pkg)
other_exception = 'Tehtävän {0} suorittaminen epäonnistui. \
Varmista, että saat ohjelman suoritettua loppuun.'.format(pkg)
try:
return importlib.import_module(pkg)
except ModuleNotFoundError:
return AssertionError(module_not_found)
except Exception:
return AssertionError(other_exception)


def reload_module(module):
if isinstance(module, AssertionError):
raise module
importlib.reload(module)


def load(pkg, method, lang='en', err=None):
module_not_found = 'Function {1} was not found in file {0}.'.format(pkg, method)
if lang == 'fi':
module_not_found = 'Tiedostosta {0} ei löytynyt funktiota {1}.'.format(pkg, method)

if not err:
err = '{0}.{1} does not exist!'.format(pkg, method)
err = module_not_found

def fail(*args, **kwargs):
raise AssertionError(err)
Expand Down