FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
unidecode/tests/test_utility.py at master · bob1sparks/unidecode · GitHub
bob1sparks
unidecode
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
unidecode
/
tests
/
test_utility.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (54 loc) · 2.18 KB
Breadcrumbs
unidecode
/
tests
/
test_utility.py
Copy path
File metadata and controls
73 lines (54 loc) · 2.18 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# vim:ts=4 sw=4 expandtab softtabstop=4
import
os
import
locale
import
unittest
import
subprocess
import
sys
import
tempfile
import
re
here
=
os
.
path
.
dirname
(
__file__
)
# Python 2.7 does not have assertRegex
if
not
hasattr
(
unittest
.
TestCase
,
'assertRegex'
):
unittest
.
TestCase
.
assertRegex
=
lambda
self
,
text
,
exp
:
self
.
assertTrue
(
re
.
search
(
exp
,
text
))
def
get_cmd
():
sys_path
=
os
.
path
.
join
(
here
,
".."
)
return
[
sys
.
executable
,
"-c"
,
"import sys; sys.path.insert(0, '%s'); from unidecode.util import main; main()"
%
(
sys_path
,)]
def
run
(
argv
):
cmd
=
get_cmd
()
p
=
subprocess
.
Popen
(
cmd
+
argv
,
stderr
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
out
,
err
=
p
.
communicate
()
return
out
.
decode
(
'ascii'
),
err
.
decode
(
'ascii'
),
p
.
returncode
def
temp
(
content
):
f
=
tempfile
.
NamedTemporaryFile
()
f
.
write
(
content
)
f
.
flush
()
return
f
class
TestUnidecodeUtility
(
unittest
.
TestCase
):
TEST_UNICODE
=
u'
\u9769
'
TEST_ASCII
=
'Ge '
def
test_encoding_error
(
self
):
f
=
temp
(
self
.
TEST_UNICODE
.
encode
(
'sjis'
))
out
,
err
,
rc
=
run
([
'-e'
,
'utf8'
,
f
.
name
])
# Text after : ... can differ between Python versions
self
.
assertRegex
(
err
,
'^Unable to decode input: '
)
self
.
assertEqual
(
rc
,
1
)
def
test_file_specified_encoding
(
self
):
f
=
temp
(
self
.
TEST_UNICODE
.
encode
(
'sjis'
))
out
,
err
,
rc
=
run
([
'-e'
,
'sjis'
,
f
.
name
])
self
.
assertEqual
(
out
,
self
.
TEST_ASCII
)
self
.
assertEqual
(
rc
,
0
)
def
test_file_default_encoding
(
self
):
f
=
temp
(
self
.
TEST_UNICODE
.
encode
(
locale
.
getpreferredencoding
()))
out
,
err
,
rc
=
run
([
f
.
name
])
self
.
assertEqual
(
out
,
self
.
TEST_ASCII
)
self
.
assertEqual
(
rc
,
0
)
def
test_file_stdin
(
self
):
cmd
=
get_cmd
()
p
=
subprocess
.
Popen
(
cmd
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
out
,
err
=
p
.
communicate
(
self
.
TEST_UNICODE
.
encode
(
locale
.
getpreferredencoding
()))
self
.
assertEqual
(
out
.
decode
(
'ascii'
),
self
.
TEST_ASCII
)
def
test_commandline
(
self
):
out
,
err
,
rc
=
run
([
'-e'
,
'sjis'
,
'-c'
,
self
.
TEST_UNICODE
.
encode
(
'sjis'
)])
self
.
assertEqual
(
out
,
self
.
TEST_ASCII
+
'
\n
'
)
self
.
assertEqual
(
rc
,
0
)
Back
|
FazBrowse Home
|
New Git URL