Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F95198555
bibauthorid_tests.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Dec 13, 16:08
Size
4 KB
Mime Type
text/x-python
Expires
Sun, Dec 15, 16:08 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22948536
Attached To
R3600 invenio-infoscience
bibauthorid_tests.py
View Options
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2011 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
import
unittest
import
bibauthorid_tables_utils
as
baidtu
import
bibauthorid_utils
as
baidu
import
bibauthorid_authorname_utils
as
bau
from
invenio.testutils
import
make_test_suite
,
run_test_suite
class
TestSplitNameParts
(
unittest
.
TestCase
):
"""Test for the functionality of splitting name strings in parts"""
def
test_split_name_parts
(
self
):
"""bibauthorid - test split name parts"""
self
.
assertEqual
([
'This'
,
[
'I'
,
'F'
],
[
'Isacorrect'
,
'Fullname'
]],
baidu
.
split_name_parts
(
'This, Isacorrect Fullname'
))
self
.
assertEqual
([
''
,
[],
[]],
baidu
.
split_name_parts
(
''
))
self
.
assertEqual
([
'name'
,
[
'F'
,
'I'
],
[
'Full'
,
'Inverted'
]],
baidu
.
split_name_parts
(
'full inverted name'
))
self
.
assertEqual
([
'Two Words'
,
[
'S'
,
'N'
],
[
'Surname'
,
'Name'
]],
baidu
.
split_name_parts
(
'Two Words, Surname Name'
))
self
.
assertEqual
([
'Strange+)*{ (=]&-$Char'
,
[
'N'
],
[
'Name'
]],
baidu
.
split_name_parts
(
'Strange+)*{ (=]&-$Char, Name'
))
class
TestCreateUnifiedNames
(
unittest
.
TestCase
):
def
test_create_unified_name
(
self
):
"""bibauthorid - test create unified name"""
self
.
assertEqual
(
'this, I. F. '
,
baidu
.
create_unified_name
(
'this, isa fullname'
))
self
.
assertEqual
(
'fullname, T. I. '
,
baidu
.
create_unified_name
(
'this isa fullname'
))
self
.
assertEqual
(
', '
,
baidu
.
create_unified_name
(
''
))
self
.
assertEqual
(
'Strange$![+{&]+)= Chars, T. '
,
baidu
.
create_unified_name
(
'Strange$![+{&]+)= Chars, Twonames'
))
class
TestCreateNormalizedName
(
unittest
.
TestCase
):
def
test_create_normalized_name
(
self
):
"""bibauthorid - test create normalized name"""
self
.
assertEqual
(
'this, Isa Fullname'
,
baidu
.
create_normalized_name
(
baidu
.
split_name_parts
(
'this, isa fullname'
)))
self
.
assertEqual
(
'fullname, This Isa'
,
baidu
.
create_normalized_name
(
baidu
.
split_name_parts
(
'this isa fullname'
)))
self
.
assertEqual
(
'Strange&][{}) ==}{$*]!, Name'
,
baidu
.
create_normalized_name
(
baidu
.
split_name_parts
(
'Strange&][{}) ==}{$*]!, Name'
)))
self
.
assertEqual
(
','
,
baidu
.
create_normalized_name
(
baidu
.
split_name_parts
(
''
)))
class
TestCleanNameString
(
unittest
.
TestCase
):
def
test_clean_name_string
(
self
):
"""bibauthorid - test crean name string"""
self
.
assertEqual
(
'this is a full name'
,
baidu
.
clean_name_string
(
'this is a full name'
))
self
.
assertEqual
(
'this is a full ,. pz'
,
baidu
.
clean_name_string
(
'this is a full ;,.$&[{{}}(=*)+]pz'
))
self
.
assertEqual
(
''
,
baidu
.
clean_name_string
(
''
))
class
TestCompareNames
(
unittest
.
TestCase
):
def
test_compare_names
(
self
):
"""bibauthorid - test compare names"""
self
.
assertEqual
(
0.94999999999999996
,
bau
.
compare_names
(
'Ellis, j.'
,
'Ellis, j.'
))
self
.
assertEqual
(
1.0
,
bau
.
compare_names
(
'Ellis, john'
,
'Ellis, john'
))
self
.
assertEqual
(
1.0
,
bau
.
compare_names
(
'John Ellis'
,
'John Ellis'
))
# self.assertEqual(0.94999999999999996,
# bau.compare_names('J. Ellis','J. Ellis'))
self
.
assertEqual
(
0.0
,
bau
.
compare_names
(
'John Ellis'
,
'John Mark'
))
self
.
assertEqual
(
0.0
,
bau
.
compare_names
(
'Ellis, John'
,
'Mark, John'
))
self
.
assertEqual
(
0.0
,
bau
.
compare_names
(
''
,
''
))
TEST_SUITE
=
make_test_suite
(
TestSplitNameParts
,
TestCreateUnifiedNames
,
TestCreateNormalizedName
,
TestCleanNameString
,
TestCompareNames
,)
if
__name__
==
"__main__"
:
run_test_suite
(
TEST_SUITE
)
Event Timeline
Log In to Comment