Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/system/user_unittest.py

Issue 2901963002: Remove unused methods from common.system.User. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Tools/Scripts/webkitpy/common/system/user_mock.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2010 Research in Motion Ltd. All rights reserved. 1 # Copyright (C) 2010 Research in Motion Ltd. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 raw_input=mock_raw_input), UserTest.example _user_response) 48 raw_input=mock_raw_input), UserTest.example _user_response)
49 49
50 def test_prompt_when_exceeded_repeats(self): 50 def test_prompt_when_exceeded_repeats(self):
51 self.repeatsRemaining = 2 51 self.repeatsRemaining = 2
52 52
53 def mock_raw_input(message): 53 def mock_raw_input(message):
54 self.repeatsRemaining -= 1 54 self.repeatsRemaining -= 1
55 return None 55 return None
56 self.assertIsNone(User.prompt('input', repeat=self.repeatsRemaining, raw _input=mock_raw_input)) 56 self.assertIsNone(User.prompt('input', repeat=self.repeatsRemaining, raw _input=mock_raw_input))
57 57
58 def test_prompt_with_multiple_lists(self):
59 def run_prompt_test(inputs, expected_result, can_choose_multiple=False):
60 def mock_raw_input(message):
61 return inputs.pop(0)
62 output_capture = OutputCapture()
63 actual_result = output_capture.assert_outputs(
64 self,
65 User.prompt_with_multiple_lists,
66 args=['title', ['subtitle1', 'subtitle2'], [['foo', 'bar'], ['fo obar', 'barbaz', 'foobaz']]],
67 kwargs={'can_choose_multiple': can_choose_multiple, 'raw_input': mock_raw_input},
68 expected_stdout='title\n\nsubtitle1\n 1. foo\n 2. bar\n\nsubtitl e2\n 3. foobar\n 4. barbaz\n 5. foobaz\n')
69 self.assertEqual(actual_result, expected_result)
70 self.assertEqual(len(inputs), 0)
71
72 run_prompt_test(['1'], 'foo')
73 run_prompt_test(['badinput', '2'], 'bar')
74 run_prompt_test(['3'], 'foobar')
75 run_prompt_test(['4'], 'barbaz')
76 run_prompt_test(['5'], 'foobaz')
77
78 run_prompt_test(['1,2'], ['foo', 'bar'], can_choose_multiple=True)
79 run_prompt_test(['1-3'], ['foo', 'bar', 'foobar'], can_choose_multiple=T rue)
80 run_prompt_test(['1-2,3'], ['foo', 'bar', 'foobar'], can_choose_multiple =True)
81 run_prompt_test(['2-1,3'], ['foobar'], can_choose_multiple=True)
82 run_prompt_test([' 1, 2 '], ['foo', 'bar'], can_choose_multiple=True )
83 run_prompt_test(['all'], ['foo', 'bar', 'foobar', 'barbaz', 'foobaz'], c an_choose_multiple=True)
84 run_prompt_test([''], ['foo', 'bar', 'foobar', 'barbaz', 'foobaz'], can_ choose_multiple=True)
85 run_prompt_test([' '], ['foo', 'bar', 'foobar', 'barbaz', 'foobaz'], ca n_choose_multiple=True)
86 run_prompt_test(['badinput', 'all'], ['foo', 'bar', 'foobar', 'barbaz', 'foobaz'], can_choose_multiple=True)
87
88 def test_prompt_with_list(self): 58 def test_prompt_with_list(self):
89 def run_prompt_test(inputs, expected_result, can_choose_multiple=False): 59 def run_prompt_test(inputs, expected_result, can_choose_multiple=False):
90 def mock_raw_input(message): 60 def mock_raw_input(message):
91 return inputs.pop(0) 61 return inputs.pop(0)
92 output_capture = OutputCapture() 62 output_capture = OutputCapture()
93 actual_result = output_capture.assert_outputs( 63 actual_result = output_capture.assert_outputs(
94 self, 64 self,
95 User.prompt_with_list, 65 User.prompt_with_list,
96 args=['title', ['foo', 'bar']], 66 args=['title', ['foo', 'bar']],
97 kwargs={'can_choose_multiple': can_choose_multiple, 'raw_input': mock_raw_input}, 67 kwargs={'can_choose_multiple': can_choose_multiple, 'raw_input': mock_raw_input},
(...skipping 25 matching lines...) Expand all
123 for test_case in test_cases: 93 for test_case in test_cases:
124 expected, inputs = test_case 94 expected, inputs = test_case
125 95
126 def mock_raw_input(message): 96 def mock_raw_input(message):
127 self.assertEqual(expected[0], message) 97 self.assertEqual(expected[0], message)
128 return inputs[1] 98 return inputs[1]
129 99
130 result = User().confirm(default=inputs[0], 100 result = User().confirm(default=inputs[0],
131 raw_input=mock_raw_input) 101 raw_input=mock_raw_input)
132 self.assertEqual(expected[1], result) 102 self.assertEqual(expected[1], result)
OLDNEW
« no previous file with comments | « third_party/WebKit/Tools/Scripts/webkitpy/common/system/user_mock.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698