Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
3fdaacac
Commit
3fdaacac
authored
May 22, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better mock Unit object model for testing
parent
ec516f66
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
45 deletions
+63
-45
trans/tests/checks.py
trans/tests/checks.py
+28
-10
trans/tests/format_checks.py
trans/tests/format_checks.py
+26
-26
trans/tests/same_checks.py
trans/tests/same_checks.py
+2
-2
trans/tests/source_checks.py
trans/tests/source_checks.py
+7
-7
No files found.
trans/tests/checks.py
View file @
3fdaacac
...
...
@@ -27,7 +27,7 @@ import uuid
from
trans.checks.base
import
Check
class
Language
(
object
):
class
Mock
Language
(
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
Mock
Unit
(
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
=
Mock
Translation
(
code
)
class
CheckTestCase
(
TestCase
):
...
...
@@ -79,7 +97,7 @@ class CheckTestCase(TestCase):
self
.
check
.
check_single
(
data
[
0
],
data
[
1
],
Unit
(
None
,
data
[
2
],
lang
),
Mock
Unit
(
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
])
Mock
Unit
(
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
])
Mock
Unit
(
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
])
Mock
Unit
(
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
])
Mock
Unit
(
None
,
self
.
test_failure_1
[
2
])
)
)
trans/tests/format_checks.py
View file @
3fdaacac
...
...
@@ -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
Mock
Unit
class
PythonFormatCheckTest
(
TestCase
):
...
...
@@ -37,7 +37,7 @@ class PythonFormatCheckTest(TestCase):
self
.
assertFalse
(
self
.
check
.
check_format
(
'strins'
,
'string'
,
Unit
(
'python_no_format'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'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'
),
Mock
Unit
(
'c_wrong_named_format'
),
0
,
False
))
trans/tests/same_checks.py
View file @
3fdaacac
...
...
@@ -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
Mock
Unit
,
CheckTestCase
class
SameCheckTest
(
CheckTestCase
):
...
...
@@ -41,7 +41,7 @@ class SameCheckTest(CheckTestCase):
self
.
assertFalse
(
self
.
check
.
check_single
(
'source'
,
'source'
,
Unit
(
code
=
'en'
),
Mock
Unit
(
code
=
'en'
),
0
))
...
...
trans/tests/source_checks.py
View file @
3fdaacac
...
...
@@ -27,7 +27,7 @@ from trans.checks.source import (
OptionalPluralCheck
,
EllipsisCheck
,
)
from
trans.tests.checks
import
Unit
from
trans.tests.checks
import
Mock
Unit
class
OptionalPluralCheckTest
(
TestCase
):
...
...
@@ -38,7 +38,7 @@ class OptionalPluralCheckTest(TestCase):
self
.
assertFalse
(
self
.
check
.
check_source
(
[
'text'
],
Unit
(),
Mock
Unit
(),
)
)
...
...
@@ -46,7 +46,7 @@ class OptionalPluralCheckTest(TestCase):
self
.
assertFalse
(
self
.
check
.
check_source
(
[
'text'
,
'texts'
],
Unit
(),
Mock
Unit
(),
)
)
...
...
@@ -54,7 +54,7 @@ class OptionalPluralCheckTest(TestCase):
self
.
assertTrue
(
self
.
check
.
check_source
(
[
'text(s)'
],
Unit
(),
Mock
Unit
(),
)
)
...
...
@@ -67,7 +67,7 @@ class EllipsisCheckTest(TestCase):
self
.
assertFalse
(
self
.
check
.
check_source
(
[
'text'
],
Unit
(),
Mock
Unit
(),
)
)
...
...
@@ -75,7 +75,7 @@ class EllipsisCheckTest(TestCase):
self
.
assertFalse
(
self
.
check
.
check_source
(
[
u'text…'
],
Unit
(),
Mock
Unit
(),
)
)
...
...
@@ -83,6 +83,6 @@ class EllipsisCheckTest(TestCase):
self
.
assertTrue
(
self
.
check
.
check_source
(
[
'text...'
],
Unit
(),
Mock
Unit
(),
)
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment