Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f31310e6
authored
Mar 19, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: test HumanSortField
parent
912ccc1b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
circle/common/tests/test_models.py
+35
-0
No files found.
circle/common/tests/test_models.py
View file @
f31310e6
from
collections
import
deque
from
django.test
import
TestCase
from
mock
import
MagicMock
from
.models
import
TestClass
from
..models
import
HumanSortField
class
MethodCacheTestCase
(
TestCase
):
...
...
@@ -28,3 +33,33 @@ class MethodCacheTestCase(TestCase):
t1
.
method
(
'a'
)
self
.
assertEqual
(
val1a
,
val1b
)
self
.
assertEqual
(
t1
.
called
,
2
)
class
TestHumanSortField
(
TestCase
):
def
test_partition
(
self
):
values
=
{(
lambda
s
:
s
.
isdigit
(),
"1234abc56"
):
(
"1234"
,
"abc"
,
"56"
),
(
lambda
s
:
s
.
isalpha
(),
"abc567"
):
(
"abc"
,
"567"
,
""
),
(
lambda
s
:
s
==
"a"
,
"aaababaa"
):
(
"aaa"
,
"b"
,
"abaa"
),
(
lambda
s
:
s
==
"a"
,
u"aaababaa"
):
(
"aaa"
,
"b"
,
"abaa"
),
}
for
(
pred
,
val
),
result
in
values
.
iteritems
():
a
,
b
,
c
=
HumanSortField
.
_partition
(
deque
(
val
),
pred
)
assert
isinstance
(
c
,
deque
)
c
=
''
.
join
(
c
)
# print "%s, %s => %s" % (val, str(pred), str((a, b, c)))
self
.
assertEquals
((
a
,
b
,
c
),
result
)
def
test_get_normalized
(
self
):
values
=
{(
"1234abc56"
,
4
):
"1234abc0056"
,
(
"abc567"
,
2
):
"abc567"
,
(
"aaababaa"
,
8
):
"aaababaa"
,
(
"aa4ababaa"
,
2
):
"aa04ababaa"
,
(
"aa4aba24baa4"
,
4
):
"aa0004aba0024baa0004"
,
}
for
(
val
,
length
),
result
in
values
.
iteritems
():
obj
=
MagicMock
(
spec
=
HumanSortField
,
maximum_number_length
=
length
,
_partition
=
HumanSortField
.
_partition
)
test_result
=
HumanSortField
.
get_normalized_value
(
obj
,
val
)
self
.
assertEquals
(
test_result
,
result
)
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