Repository navigation
Expand file tree
/
Copy pathtest_utils.py
More file actions
122 lines (95 loc) · 4.74 KB
/
Copy pathtest_utils.py
File metadata and controls
122 lines (95 loc) · 4.74 KB
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
# Copyright 2013 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 signal
import platform
import os
from awscli.testutils import unittest, skip_if_windows
from awscli.utils import (split_on_commas, ignore_ctrl_c,
find_service_and_method_in_event_name)
class TestCSVSplit(unittest.TestCase):
def test_normal_csv_split(self):
self.assertEqual(split_on_commas('foo,bar,baz'),
['foo', 'bar', 'baz'])
def test_quote_split(self):
self.assertEqual(split_on_commas('foo,"bar",baz'),
['foo', 'bar', 'baz'])
def test_inner_quote_split(self):
self.assertEqual(split_on_commas('foo,bar="1,2,3",baz'),
['foo', 'bar=1,2,3', 'baz'])
def test_single_quote(self):
self.assertEqual(split_on_commas("foo,bar='1,2,3',baz"),
['foo', 'bar=1,2,3', 'baz'])
def test_mixing_double_single_quotes(self):
self.assertEqual(split_on_commas("""foo,bar="1,'2',3",baz"""),
['foo', "bar=1,'2',3", 'baz'])
def test_mixing_double_single_quotes_before_first_comma(self):
self.assertEqual(split_on_commas("""foo,bar="1','2',3",baz"""),
['foo', "bar=1','2',3", 'baz'])
def test_inner_quote_split_with_equals(self):
self.assertEqual(split_on_commas('foo,bar="Foo:80/bar?a=b",baz'),
['foo', 'bar=Foo:80/bar?a=b', 'baz'])
def test_single_quoted_inner_value_with_no_commas(self):
self.assertEqual(split_on_commas("foo,bar='BAR',baz"),
['foo', 'bar=BAR', 'baz'])
def test_escape_quotes(self):
self.assertEqual(split_on_commas('foo,bar=1\,2\,3,baz'),
['foo', 'bar=1,2,3', 'baz'])
def test_no_commas(self):
self.assertEqual(split_on_commas('foo'), ['foo'])
def test_trailing_commas(self):
self.assertEqual(split_on_commas('foo,'), ['foo', ''])
def test_escape_backslash(self):
self.assertEqual(split_on_commas('foo,bar\\\\,baz\\\\,qux'),
['foo', 'bar\\', 'baz\\', 'qux'])
def test_square_brackets(self):
self.assertEqual(split_on_commas('foo,bar=["a=b",\'2\',c=d],baz'),
['foo', 'bar=a=b,2,c=d', 'baz'])
def test_quoted_square_brackets(self):
self.assertEqual(split_on_commas('foo,bar="[blah]",c=d],baz'),
['foo', 'bar=[blah]', 'c=d]', 'baz'])
def test_missing_bracket(self):
self.assertEqual(split_on_commas('foo,bar=[a,baz'),
['foo', 'bar=[a', 'baz'])
def test_missing_bracket2(self):
self.assertEqual(split_on_commas('foo,bar=a],baz'),
['foo', 'bar=a]', 'baz'])
def test_bracket_in_middle(self):
self.assertEqual(split_on_commas('foo,bar=a[b][c],baz'),
['foo', 'bar=a[b][c]', 'baz'])
def test_end_bracket_in_value(self):
self.assertEqual(split_on_commas('foo,bar=[foo,*[biz]*,baz]'),
['foo', 'bar=foo,*[biz]*,baz'])
@skip_if_windows("Ctrl-C not supported on windows.")
class TestIgnoreCtrlC(unittest.TestCase):
def test_ctrl_c_is_ignored(self):
with ignore_ctrl_c():
# Should have the noop signal handler installed.
self.assertEqual(signal.getsignal(signal.SIGINT), signal.SIG_IGN)
# And if we actually try to sigint ourselves, an exception
# should not propogate.
os.kill(os.getpid(), signal.SIGINT)
class TestFindServiceAndOperationNameFromEvent(unittest.TestCase):
def test_finds_service_and_operation_name(self):
event_name = "foo.bar.baz"
service, operation = find_service_and_method_in_event_name(event_name)
self.assertEqual(service, "bar")
self.assertEqual(operation, "baz")
def test_returns_none_if_event_is_too_short(self):
event_name = "foo.bar"
service, operation = find_service_and_method_in_event_name(event_name)
self.assertEqual(service, "bar")
self.assertIs(operation, None)
event_name = "foo"
service, operation = find_service_and_method_in_event_name(event_name)
self.assertIs(service, None)
self.assertIs(operation, None)