FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
aws-cli/tests/unit/test_compat.py at develop · lovejavaee/aws-cli · GitHub
lovejavaee
/
aws-cli
Public
forked from
aws/aws-cli
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
aws-cli
/
tests
/
unit
/
test_compat.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
154 lines (130 loc) · 5.17 KB
Breadcrumbs
aws-cli
/
tests
/
unit
/
test_compat.py
Copy path
File metadata and controls
154 lines (130 loc) · 5.17 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import
os
import
signal
import
pytest
from
botocore
.
compat
import
six
from
awscli
.
compat
import
ensure_text_type
from
awscli
.
compat
import
compat_shell_quote
from
awscli
.
compat
import
get_popen_kwargs_for_pager_cmd
from
awscli
.
compat
import
ignore_user_entered_signals
from
awscli
.
testutils
import
mock
,
unittest
,
skip_if_windows
class
TestEnsureText
(
unittest
.
TestCase
):
def
test_string
(
self
):
value
=
'foo'
response
=
ensure_text_type
(
value
)
self
.
assertIsInstance
(
response
,
six
.
text_type
)
self
.
assertEqual
(
response
,
'foo'
)
def
test_binary
(
self
):
value
=
b'bar'
response
=
ensure_text_type
(
value
)
self
.
assertIsInstance
(
response
,
six
.
text_type
)
self
.
assertEqual
(
response
,
'bar'
)
def
test_unicode
(
self
):
value
=
u'baz'
response
=
ensure_text_type
(
value
)
self
.
assertIsInstance
(
response
,
six
.
text_type
)
self
.
assertEqual
(
response
,
'baz'
)
def
test_non_ascii
(
self
):
value
=
b'
\xe2
\x9c
\x93
'
response
=
ensure_text_type
(
value
)
self
.
assertIsInstance
(
response
,
six
.
text_type
)
self
.
assertEqual
(
response
,
u'
\u2713
'
)
def
test_non_string_or_bytes_raises_error
(
self
):
value
=
500
with
self
.
assertRaises
(
ValueError
):
ensure_text_type
(
value
)
@
pytest
.
mark
.
parametrize
(
"input_string, expected_output"
,
(
(
''
,
'""'
),
(
'"'
,
'
\\
"'
),
(
'
\\
'
,
'
\\
'
),
(
'
\\
a'
,
'
\\
a'
),
(
'
\\
\\
'
,
'
\\
\\
'
),
(
'
\\
"'
,
'
\\
\\
\\
"'
),
(
'
\\
\\
"'
,
'
\\
\\
\\
\\
\\
"'
),
(
'foo bar'
,
'"foo bar"'
),
(
'foo
\t
bar'
,
'"foo
\t
bar"'
),
)
)
def
test_compat_shell_quote_windows
(
input_string
,
expected_output
):
assert
compat_shell_quote
(
input_string
,
"win32"
)
==
expected_output
@
pytest
.
mark
.
parametrize
(
"input_string, expected_output"
,
(
(
''
,
"''"
),
(
'*'
,
"'*'"
),
(
'foo'
,
'foo'
),
(
'foo bar'
,
"'foo bar'"
),
(
'foo
\t
bar'
,
"'foo
\t
bar'"
),
(
'foo
\n
bar'
,
"'foo
\n
bar'"
),
(
"foo'bar"
,
'
\'
foo
\'
"
\'
"
\'
bar
\'
'
)
)
)
def
test_comat_shell_quote_linux
(
input_string
,
expected_output
):
assert
compat_shell_quote
(
input_string
,
"linux2"
)
==
expected_output
@
pytest
.
mark
.
parametrize
(
"input_string, expected_output"
,
(
(
''
,
"''"
),
(
'*'
,
"'*'"
),
(
'foo'
,
'foo'
),
(
'foo bar'
,
"'foo bar'"
),
(
'foo
\t
bar'
,
"'foo
\t
bar'"
),
(
'foo
\n
bar'
,
"'foo
\n
bar'"
),
(
"foo'bar"
,
'
\'
foo
\'
"
\'
"
\'
bar
\'
'
)
)
)
def
test_comat_shell_quote_darwin
(
input_string
,
expected_output
):
assert
compat_shell_quote
(
input_string
,
"darwin"
)
==
expected_output
class
TestGetPopenPagerCmd
(
unittest
.
TestCase
):
@
mock
.
patch
(
'awscli.compat.is_windows'
,
True
)
@
mock
.
patch
(
'awscli.compat.default_pager'
,
'more'
)
def
test_windows
(
self
):
kwargs
=
get_popen_kwargs_for_pager_cmd
()
self
.
assertEqual
({
'args'
:
'more'
,
'shell'
:
True
},
kwargs
)
@
mock
.
patch
(
'awscli.compat.is_windows'
,
True
)
@
mock
.
patch
(
'awscli.compat.default_pager'
,
'more'
)
def
test_windows_with_specific_pager
(
self
):
kwargs
=
get_popen_kwargs_for_pager_cmd
(
'less -R'
)
self
.
assertEqual
({
'args'
:
'less -R'
,
'shell'
:
True
},
kwargs
)
@
mock
.
patch
(
'awscli.compat.is_windows'
,
False
)
@
mock
.
patch
(
'awscli.compat.default_pager'
,
'less -R'
)
def
test_non_windows
(
self
):
kwargs
=
get_popen_kwargs_for_pager_cmd
()
self
.
assertEqual
({
'args'
: [
'less'
,
'-R'
]},
kwargs
)
@
mock
.
patch
(
'awscli.compat.is_windows'
,
False
)
@
mock
.
patch
(
'awscli.compat.default_pager'
,
'less -R'
)
def
test_non_windows_specific_pager
(
self
):
kwargs
=
get_popen_kwargs_for_pager_cmd
(
'more'
)
self
.
assertEqual
({
'args'
: [
'more'
]},
kwargs
)
class
TestIgnoreUserSignals
(
unittest
.
TestCase
):
@
skip_if_windows
(
"These signals are not supported for windows"
)
def
test_ignore_signal_sigint
(
self
):
with
ignore_user_entered_signals
():
try
:
os
.
kill
(
os
.
getpid
(),
signal
.
SIGINT
)
except
KeyboardInterrupt
:
self
.
fail
(
'The ignore_user_entered_signals context '
'manager should have ignored'
)
@
skip_if_windows
(
"These signals are not supported for windows"
)
def
test_ignore_signal_sigquit
(
self
):
with
ignore_user_entered_signals
():
self
.
assertEqual
(
signal
.
getsignal
(
signal
.
SIGQUIT
),
signal
.
SIG_IGN
)
os
.
kill
(
os
.
getpid
(),
signal
.
SIGQUIT
)
@
skip_if_windows
(
"These signals are not supported for windows"
)
def
test_ignore_signal_sigtstp
(
self
):
with
ignore_user_entered_signals
():
self
.
assertEqual
(
signal
.
getsignal
(
signal
.
SIGTSTP
),
signal
.
SIG_IGN
)
os
.
kill
(
os
.
getpid
(),
signal
.
SIGTSTP
)
Back
|
FazBrowse Home
|
New Git URL