This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from freedomofkeima/add-tests
Add pytest and CircleCI 2 integration
- Loading branch information
Showing
9 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
working_directory: ~/circleci-maidchan | ||
docker: | ||
- image: circleci/python:2.7 | ||
steps: | ||
- checkout | ||
- restore_cache: | ||
key: deps1-{{ .Branch }} | ||
- run: | ||
command: | | ||
virtualenv venv | ||
. venv/bin/activate | ||
pip install -r requirements.txt | ||
pip install -r requirements-dev.txt | ||
- save_cache: | ||
key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }} | ||
paths: | ||
- "venv" | ||
- run: | ||
command: | | ||
. venv/bin/activate | ||
mkdir -p "${CIRCLE_WORKING_DIRECTORY}/results/junit/" | ||
pytest --junitxml="results/junit/results-${CIRCLE_NODE_INDEX}.xml" --verbose --cov=maidchan --cov-report term-missing tests | ||
- store_artifacts: | ||
path: "results" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
*.pyc | ||
/build | ||
/venv | ||
.cache/ | ||
.coverage | ||
|
||
# Packages | ||
*.egg | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
coverage==4.4.1 | ||
funcsigs==1.0.2 | ||
mock==2.0.0 | ||
pbr==3.1.1 | ||
py==1.4.34 | ||
pytest==3.2.3 | ||
pytest-cov==2.5.1 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
English | ||
Name English | ||
Family Indo-European | ||
Writing system Latin | ||
Code en | ||
ISO 639-3 eng | ||
SIL http://www-01.sil.org/iso639-3/documentation.asp?id=eng | ||
Glottolog http://glottolog.org/resource/languoid/id/stan1293 | ||
Wikipedia http://en.wikipedia.org/wiki/English_language |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
こんにちは世界! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Halo Dunia! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
|
||
from mock import Mock, patch | ||
|
||
from maidchan.translate import get_trans_language_prediction, get_translation | ||
|
||
SCRIPT_PATH = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
|
||
def _get_response(name): | ||
path = os.path.join(SCRIPT_PATH, 'data', name) | ||
with open(path) as f: | ||
return f.read() | ||
|
||
|
||
def mocked_trans(*args, **kwargs): | ||
""" | ||
Mocked "trans" | ||
""" | ||
process_mock = Mock() | ||
return_value = None | ||
if '-id' in args[0] and 'hello, world!' in args[0]: | ||
return_value = _get_response('get_trans_prediction.txt') | ||
elif '-b' in args[0] and 'en:ja' in args[0] and 'hello, world!' in args[0]: | ||
return_value = _get_response('get_trans_translation.txt') | ||
elif '-b' in args[0] and 'en:id' in args[0] and 'hello, world!' in args[0]: | ||
return_value = _get_response('get_trans_translation_2.txt') | ||
attrs = {'communicate.return_value': (return_value, None)} | ||
process_mock.configure_mock(**attrs) | ||
return process_mock | ||
|
||
|
||
class TestTranslate: | ||
@patch('subprocess.Popen', side_effect=mocked_trans) | ||
def test_get_translate_language_prediction(self, mock_trans): | ||
assert get_trans_language_prediction("hello, world!") == "en" | ||
|
||
@patch('subprocess.Popen', side_effect=mocked_trans) | ||
def test_get_translation_en_to_ja(self, mock_trans): | ||
query = "translate hello, world! from english to japanese" | ||
assert get_translation(query).decode('utf-8') == u"こんにちは世界!" | ||
|
||
@patch('subprocess.Popen', side_effect=mocked_trans) | ||
def test_get_translation_en_to_default(self, mock_trans): | ||
query = "translate hello, world! from english" | ||
assert get_translation(query).decode('utf-8') == u"こんにちは世界!" | ||
|
||
@patch('subprocess.Popen', side_effect=mocked_trans) | ||
def test_get_translation_default_to_id(self, mock_trans): | ||
query = "translate hello, world! to bahasa" | ||
assert get_translation(query).decode('utf-8') == "Halo Dunia!" |