Skip to content

Instantly share code, notes, and snippets.

@mokevnin
Last active January 27, 2016 15:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mokevnin/3e29f26bfde04ef1588e to your computer and use it in GitHub Desktop.
Save mokevnin/3e29f26bfde04ef1588e to your computer and use it in GitHub Desktop.
python handler for battle.hexlet.io
import atexit
import fileinput
import os
import json
import unittest
class TestSolution(unittest.TestCase):
maxDiff = None
def test_solution(self):
checks = [json.loads(line) for line in fileinput.input()]
import solution
for check in checks:
expected = check['expected']
arguments = check['arguments']
if 'check' in check:
atexit.register(onexit, check['check'])
else:
msg = "Arguments was: %s" % arguments
self.assertEqual(expected, solution.solution(*arguments), msg)
def onexit(msg):
print(msg)
if __name__ == '__main__':
unittest.main()
{"expected": {"one": 5, "two": 5}, "arguments": [["one", "two"], 5]}
{"expected": {"one": 3}, "arguments": [["one"], 3]}
FROM hexlet/hexlet-base
RUN apt-install python-pip python-dev
RUN apt-install python3-pip python3-dev
RUN pip3 install pytest
ENV PYTHONDONTWRITEBYTECODE 1
test:
@cat data.jsons | sudo -u nobody python3 checker.py
.PHONY: test
# BEGIN python3
def solution(l, d):
return {v: d for v in l}
# END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment