Commit 3fdaacac authored by Michal Čihař's avatar Michal Čihař

Better mock Unit object model for testing

parent ec516f66
......@@ -27,7 +27,7 @@ import uuid
from trans.checks.base import Check
class Language(object):
class MockLanguage(object):
'''
Mock language object.
'''
......@@ -35,15 +35,33 @@ class Language(object):
self.code = code
class Translation(object):
class MockProject(object):
'''
Mock project object.
'''
def __init__(self):
self.id = 1
class MockSubProject(object):
'''
Mock subproject object.
'''
def __init__(self):
self.id = 1
self.project= MockProject()
class MockTranslation(object):
'''
Mock translation object.
'''
def __init__(self, code='cs'):
self.language = Language(code)
self.language = MockLanguage(code)
self.subproject= MockSubProject()
class Unit(object):
class MockUnit(object):
'''
Mock unit object.
'''
......@@ -52,7 +70,7 @@ class Unit(object):
checksum = str(uuid.uuid1())
self.checksum = checksum
self.flags = flags
self.translation = Translation(code)
self.translation = MockTranslation(code)
class CheckTestCase(TestCase):
......@@ -79,7 +97,7 @@ class CheckTestCase(TestCase):
self.check.check_single(
data[0],
data[1],
Unit(None, data[2], lang),
MockUnit(None, data[2], lang),
0
),
expected
......@@ -111,7 +129,7 @@ class CheckTestCase(TestCase):
self.check.check(
[self.test_good_matching[0]],
[self.test_good_matching[1]],
Unit(None, self.test_good_matching[2])
MockUnit(None, self.test_good_matching[2])
)
)
......@@ -120,7 +138,7 @@ class CheckTestCase(TestCase):
self.check.check(
[self.test_good_matching[0]] * 2,
[self.test_good_matching[1]] * 3,
Unit(None, self.test_good_matching[2])
MockUnit(None, self.test_good_matching[2])
)
)
......@@ -131,7 +149,7 @@ class CheckTestCase(TestCase):
self.check.check(
[self.test_failure_1[0]],
[self.test_failure_1[1]],
Unit(None, self.test_failure_1[2])
MockUnit(None, self.test_failure_1[2])
)
)
......@@ -142,6 +160,6 @@ class CheckTestCase(TestCase):
self.check.check(
[self.test_failure_1[0]] * 2,
[self.test_failure_1[1]] * 3,
Unit(None, self.test_failure_1[2])
MockUnit(None, self.test_failure_1[2])
)
)
......@@ -26,7 +26,7 @@ from django.test import TestCase
from trans.checks.format import (
PythonFormatCheck, PHPFormatCheck, CFormatCheck,
)
from trans.tests.checks import Unit
from trans.tests.checks import MockUnit
class PythonFormatCheckTest(TestCase):
......@@ -37,7 +37,7 @@ class PythonFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
'strins',
'string',
Unit('python_no_format'),
MockUnit('python_no_format'),
0,
False
))
......@@ -46,7 +46,7 @@ class PythonFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
u'%s string',
u'%s string',
Unit('python_format'),
MockUnit('python_format'),
0,
False
))
......@@ -55,7 +55,7 @@ class PythonFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
u'%d%% string',
u'%d%% string',
Unit('python_percent_format'),
MockUnit('python_percent_format'),
0,
False
))
......@@ -64,7 +64,7 @@ class PythonFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
u'%(name)s string',
u'%(name)s string',
Unit('python_named_format'),
MockUnit('python_named_format'),
0,
False
))
......@@ -73,7 +73,7 @@ class PythonFormatCheckTest(TestCase):
self.assertTrue(self.check.check_format(
u'%s string',
u'string',
Unit('python_missing_format'),
MockUnit('python_missing_format'),
0,
False
))
......@@ -82,7 +82,7 @@ class PythonFormatCheckTest(TestCase):
self.assertTrue(self.check.check_format(
u'%(name)s string',
u'string',
Unit('python_missing_named_format'),
MockUnit('python_missing_named_format'),
0,
False
))
......@@ -91,7 +91,7 @@ class PythonFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
u'%(name)s string',
u'string',
Unit('python_missing_named_format'),
MockUnit('python_missing_named_format'),
0,
True
))
......@@ -100,7 +100,7 @@ class PythonFormatCheckTest(TestCase):
self.assertTrue(self.check.check_format(
u'%s string',
u'%c string',
Unit('python_wrong_format'),
MockUnit('python_wrong_format'),
0,
False
))
......@@ -109,7 +109,7 @@ class PythonFormatCheckTest(TestCase):
self.assertTrue(self.check.check_format(
u'%(name)s string',
u'%(jmeno)s string',
Unit('python_wrong_named_format'),
MockUnit('python_wrong_named_format'),
0,
False
))
......@@ -123,7 +123,7 @@ class PHPFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
'strins',
'string',
Unit('php_no_format'),
MockUnit('php_no_format'),
0,
False
))
......@@ -132,7 +132,7 @@ class PHPFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
u'%s string',
u'%s string',
Unit('php_format'),
MockUnit('php_format'),
0,
False
))
......@@ -141,7 +141,7 @@ class PHPFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
u'%1$s string',
u'%1$s string',
Unit('php_named_format'),
MockUnit('php_named_format'),
0,
False
))
......@@ -150,7 +150,7 @@ class PHPFormatCheckTest(TestCase):
self.assertTrue(self.check.check_format(
u'%s string',
u'string',
Unit('php_missing_format'),
MockUnit('php_missing_format'),
0,
False
))
......@@ -159,7 +159,7 @@ class PHPFormatCheckTest(TestCase):
self.assertTrue(self.check.check_format(
u'%1$s string',
u'string',
Unit('php_missing_named_format'),
MockUnit('php_missing_named_format'),
0,
False
))
......@@ -168,7 +168,7 @@ class PHPFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
u'%1$s string',
u'string',
Unit('php_missing_named_format'),
MockUnit('php_missing_named_format'),
0,
True
))
......@@ -177,7 +177,7 @@ class PHPFormatCheckTest(TestCase):
self.assertTrue(self.check.check_format(
u'%s string',
u'%c string',
Unit('php_wrong_format'),
MockUnit('php_wrong_format'),
0,
False
))
......@@ -186,7 +186,7 @@ class PHPFormatCheckTest(TestCase):
self.assertTrue(self.check.check_format(
u'%1$s string',
u'%s string',
Unit('php_wrong_named_format'),
MockUnit('php_wrong_named_format'),
0,
False
))
......@@ -200,7 +200,7 @@ class CFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
'strins',
'string',
Unit('c_no_format'),
MockUnit('c_no_format'),
0,
False
))
......@@ -209,7 +209,7 @@ class CFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
u'%s string',
u'%s string',
Unit('c_format'),
MockUnit('c_format'),
0,
False
))
......@@ -218,7 +218,7 @@ class CFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
u'%10s string',
u'%10s string',
Unit('c_named_format'),
MockUnit('c_named_format'),
0,
False
))
......@@ -227,7 +227,7 @@ class CFormatCheckTest(TestCase):
self.assertTrue(self.check.check_format(
u'%s string',
u'string',
Unit('c_missing_format'),
MockUnit('c_missing_format'),
0,
False
))
......@@ -236,7 +236,7 @@ class CFormatCheckTest(TestCase):
self.assertTrue(self.check.check_format(
u'%10s string',
u'string',
Unit('c_missing_named_format'),
MockUnit('c_missing_named_format'),
0,
False
))
......@@ -245,7 +245,7 @@ class CFormatCheckTest(TestCase):
self.assertFalse(self.check.check_format(
u'%10s string',
u'string',
Unit('c_missing_named_format'),
MockUnit('c_missing_named_format'),
0,
True
))
......@@ -254,7 +254,7 @@ class CFormatCheckTest(TestCase):
self.assertTrue(self.check.check_format(
u'%s string',
u'%c string',
Unit('c_wrong_format'),
MockUnit('c_wrong_format'),
0,
False
))
......@@ -263,7 +263,7 @@ class CFormatCheckTest(TestCase):
self.assertTrue(self.check.check_format(
u'%10s string',
u'%20s string',
Unit('c_wrong_named_format'),
MockUnit('c_wrong_named_format'),
0,
False
))
......@@ -25,7 +25,7 @@ Tests for quality checks.
from trans.checks.same import (
SameCheck,
)
from trans.tests.checks import Unit, CheckTestCase
from trans.tests.checks import MockUnit, CheckTestCase
class SameCheckTest(CheckTestCase):
......@@ -41,7 +41,7 @@ class SameCheckTest(CheckTestCase):
self.assertFalse(self.check.check_single(
'source',
'source',
Unit(code='en'),
MockUnit(code='en'),
0
))
......
......@@ -27,7 +27,7 @@ from trans.checks.source import (
OptionalPluralCheck,
EllipsisCheck,
)
from trans.tests.checks import Unit
from trans.tests.checks import MockUnit
class OptionalPluralCheckTest(TestCase):
......@@ -38,7 +38,7 @@ class OptionalPluralCheckTest(TestCase):
self.assertFalse(
self.check.check_source(
['text'],
Unit(),
MockUnit(),
)
)
......@@ -46,7 +46,7 @@ class OptionalPluralCheckTest(TestCase):
self.assertFalse(
self.check.check_source(
['text', 'texts'],
Unit(),
MockUnit(),
)
)
......@@ -54,7 +54,7 @@ class OptionalPluralCheckTest(TestCase):
self.assertTrue(
self.check.check_source(
['text(s)'],
Unit(),
MockUnit(),
)
)
......@@ -67,7 +67,7 @@ class EllipsisCheckTest(TestCase):
self.assertFalse(
self.check.check_source(
['text'],
Unit(),
MockUnit(),
)
)
......@@ -75,7 +75,7 @@ class EllipsisCheckTest(TestCase):
self.assertFalse(
self.check.check_source(
[u'text…'],
Unit(),
MockUnit(),
)
)
......@@ -83,6 +83,6 @@ class EllipsisCheckTest(TestCase):
self.assertTrue(
self.check.check_source(
['text...'],
Unit(),
MockUnit(),
)
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment