| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
import unittest |
| 20 |
import unittest.mock |
| 21 |
from polib import POEntry, POFile |
| 22 |
import tempfile |
| 23 |
|
| 24 |
from translation_canary.translatable.test_markup import test_markup |
| 25 |
from translation_canary.translatable.test_comment import test_comment |
| 26 |
|
| 27 |
from translation_canary.translatable import testString, testPOT |
| 28 |
|
| 29 |
class TestMarkup(unittest.TestCase): |
| 30 |
def test_ok(self): |
| 31 |
|
| 32 |
test_markup(POEntry(msgid="test string")) |
| 33 |
|
| 34 |
|
| 35 |
test_markup(POEntry(msgid="<b>test</b> string")) |
| 36 |
|
| 37 |
def test_unnecessary_markup(self): |
| 38 |
self.assertRaises(AssertionError, test_markup, POEntry(msgid="<b>test string</b>")) |
| 39 |
|
| 40 |
class TestComment(unittest.TestCase): |
| 41 |
def test_ok(self): |
| 42 |
|
| 43 |
test_comment(POEntry(msgid="Hello, I am a test string")) |
| 44 |
|
| 45 |
|
| 46 |
test_comment(POEntry(msgid="c", comment="TRANSLATORS: 'c' to continue")) |
| 47 |
|
| 48 |
def test_no_comment(self): |
| 49 |
self.assertRaises(AssertionError, test_comment, POEntry(msgid="c")) |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
def _true_test(_s): |
| 54 |
pass |
| 55 |
|
| 56 |
def _false_test(_s): |
| 57 |
raise AssertionError("no good") |
| 58 |
|
| 59 |
def _picky_test(s): |
| 60 |
if s.msgstr.startswith("p"): |
| 61 |
raise AssertionError("I don't like this one") |
| 62 |
|
| 63 |
class TestTestString(unittest.TestCase): |
| 64 |
@unittest.mock.patch("translation_canary.translatable._tests", [_true_test]) |
| 65 |
def test_success(self): |
| 66 |
self.assertTrue(testString(POEntry())) |
| 67 |
|
| 68 |
@unittest.mock.patch("translation_canary.translatable._tests", [_false_test]) |
| 69 |
def test_failure(self): |
| 70 |
self.assertFalse(testString(POEntry())) |
| 71 |
|
| 72 |
@unittest.mock.patch("translation_canary.translatable._tests", [_picky_test]) |
| 73 |
class TestTestPOT(unittest.TestCase): |
| 74 |
def test_success(self): |
| 75 |
with tempfile.NamedTemporaryFile(suffix=".pot") as potfile: |
| 76 |
poobj = POFile() |
| 77 |
poobj.append(POEntry(msgstr="test string")) |
| 78 |
poobj.save(potfile.name) |
| 79 |
|
| 80 |
self.assertTrue(testPOT(potfile.name)) |
| 81 |
|
| 82 |
def test_some_failure(self): |
| 83 |
with tempfile.NamedTemporaryFile(suffix=".pot") as potfile: |
| 84 |
poobj = POFile() |
| 85 |
poobj.append(POEntry(msgstr="test string")) |
| 86 |
poobj.append(POEntry(msgstr="pest string")) |
| 87 |
poobj.save(potfile.name) |
| 88 |
|
| 89 |
self.assertFalse(testPOT(potfile.name)) |
| 90 |
|
| 91 |
def test_all_failure(self): |
| 92 |
with tempfile.NamedTemporaryFile(suffix=".pot") as potfile: |
| 93 |
poobj = POFile() |
| 94 |
poobj.append(POEntry(msgstr="pest string")) |
| 95 |
poobj.append(POEntry(msgstr="past string")) |
| 96 |
poobj.save(potfile.name) |
| 97 |
|
| 98 |
self.assertFalse(testPOT(potfile.name)) |