-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
336 additions
and
91 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
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ coveralls==1.1 | |
docopt==0.6.2 | ||
nose==1.3.7 | ||
requests==2.11.0 | ||
tabulate==0.7.7 |
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,5 +1,5 @@ | ||
/* No comment provided by engineer. */ | ||
"generate.reference.test.0" = "Test0"; | ||
"parsing.test.0" = "Test0"; | ||
|
||
/* No comment provided by engineer. */ | ||
"generate.reference.test.1" = "Test1"; | ||
"parsing.test.1" = "Test1"; |
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,95 @@ | ||
import unittest | ||
import sys | ||
import tempfile | ||
import subprocess | ||
import os | ||
from shutil import rmtree | ||
from tystrings import cli | ||
|
||
|
||
class CLIBaseTest(unittest.TestCase): | ||
def setUp(self): | ||
self.temp_path = tempfile.mkdtemp() | ||
self.cwd = self.temp_path | ||
|
||
def tearDown(self): | ||
rmtree(self.temp_path) | ||
|
||
def call(self, *new_args, **kwargs): | ||
pass | ||
|
||
def test_base(self): | ||
self.assertEqual(0, self.call('-h')) | ||
self.assertEqual(0, self.call('--version')) | ||
|
||
def test_diff(self): | ||
subcommand = 'diff' | ||
self.assertEqual(0, self.call(subcommand, '-h')) | ||
|
||
file1 = os.path.abspath('tests/example/strings/diff1.strings') | ||
file2 = os.path.abspath('tests/example/strings/diff2.strings') | ||
self.assertEqual(0, self.call(subcommand, file1, file2, '-v')) | ||
|
||
def test_lint(self): | ||
subcommand = 'lint' | ||
self.assertEqual(0, self.call(subcommand, '-h')) | ||
|
||
dst = os.path.abspath('tests/example/strings/lint.strings') | ||
self.assertEqual(1, self.call(subcommand, dst, '-v')) | ||
|
||
dst = os.path.abspath('tests/example/strings/base.strings') | ||
self.assertEqual(0, self.call(subcommand, dst, '-v')) | ||
|
||
def test_translate(self): | ||
subcommand = 'translate' | ||
self.assertEqual(0, self.call(subcommand, '-h')) | ||
|
||
src = os.path.abspath('tests/example/strings/base_translator.strings') | ||
dst = os.path.join(self.cwd, 'base_translator.strings') | ||
dst_lang = 'zh' | ||
src_lang = 'en' | ||
|
||
self.assertEqual(0, self.call(subcommand, src, dst, '--dst-lang', dst_lang, '--src-lang', src_lang)) | ||
self.assertTrue(os.path.exists(dst)) | ||
os.remove(dst) | ||
|
||
self.assertEqual(0, self.call(subcommand, src, dst, '--dst-lang', dst_lang)) | ||
self.assertTrue(os.path.exists(dst)) | ||
|
||
def test_generate(self): | ||
subcommand = 'generate' | ||
self.assertEqual(0, self.call(subcommand, '-h')) | ||
|
||
src = os.path.abspath('tests/example/IntegrationDemo.m') | ||
dst = os.path.join(self.cwd, 'generate') | ||
|
||
# input directory | ||
self.assertEqual(2, self.call(subcommand, self.cwd, '-o', dst)) | ||
# file not exists | ||
self.assertEqual(2, self.call(subcommand, 'xxxxxxx', '-o', dst)) | ||
|
||
generated_path = os.path.join(dst, 'Localizable.strings') | ||
self.assertEqual(0, self.call(subcommand, src, '-o', dst)) | ||
self.assertTrue(os.path.exists(generated_path)) | ||
rmtree(dst) | ||
|
||
self.assertEqual(0, self.call(subcommand, src, '-o', dst, '--utf8')) | ||
self.assertTrue(os.path.exists(generated_path)) | ||
|
||
|
||
# class CLITests(CLIBaseTest): | ||
# def call(self, *new_args, **kwargs): | ||
# with tempfile.TemporaryFile() as out: | ||
# args = (sys.executable, '-m', 'tystrings.cli') + new_args | ||
# return subprocess.call(args, stdout=out, stderr=out, cwd=self.cwd, **kwargs) | ||
# # return subprocess.call(args, cwd=self.cwd, **kwargs) | ||
|
||
|
||
class CLIWhiteTests(CLIBaseTest): | ||
def call(self, *new_args, **kwargs): | ||
with self.assertRaises(BaseException) as cm: | ||
cli.main(list(new_args)) | ||
return cm.exception.code | ||
|
||
# ignore base class | ||
del(CLIBaseTest) |
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
import unittest | ||
from tystrings import * | ||
|
||
|
||
class ParsingTest(unittest.TestCase): | ||
def setUp(self): | ||
self.strings = Strings() | ||
|
||
def test_base(self): | ||
result = Strings.parsing('tests/example/strings/base.strings') | ||
self.assertDictEqual(result, self._result(2)) | ||
|
||
def test_utf8(self): | ||
result = Strings.parsing('tests/example/strings/utf8.strings', encoding='utf8') | ||
self.assertDictEqual(result, self._result(2)) | ||
|
||
def test_comment(self): | ||
result = Strings.parsing('tests/example/strings/comment.strings') | ||
self.assertDictEqual(result, self._result(3)) | ||
|
||
def test_space(self): | ||
result = Strings.parsing('tests/example/strings/space.strings') | ||
right_answer = self._result(4) | ||
right_answer['parsing.test.4'] = 'Test4\nTest4\nTest4Test4Test4\nTest4\n' | ||
self.assertDictEqual(result, right_answer) | ||
|
||
@staticmethod | ||
def _result(count): | ||
result = {} | ||
|
||
for i in range(0, count): | ||
result['parsing.test.%s' % i] = 'Test%s' % i | ||
|
||
return result |
Oops, something went wrong.