FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Switch test code over to skip_if_windows · powersjcb/aws-cli@900fb63 · GitHub

forked from aws/aws-cli

Commit 900fb63

Browse files
committed
Switch test code over to skip_if_windows
This fixes an issue with test_cli, where a test needed to be annotated to be skipped on windows but was missed. I've also added a test utility function for this and I've updated all the existing skippable tests to use this decorator. This also makes is easier in the future if we need to update what qualifies as "not windows."
1 parent d8e7c04 commit 900fb63

10 files changed

Lines changed: 44 additions & 38 deletions

File tree

‎awscli/testutils.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@
8181
AWS_CMD = None
8282

8383

84+
def skip_if_windows(reason):
85+
"""Decorator to skip tests that should not be run on windows.
86+
87+
Example usage:
88+
89+
@skip_if_windows("Not valid")
90+
def test_some_non_windows_stuff(self):
91+
self.assertEqual(...)
92+
93+
"""
94+
def decorator(func):
95+
return unittest.skipIf(
96+
platform.system() not in ['Darwin', 'Linux'], reason)(func)
97+
return decorator
98+
99+
84100
def create_clidriver():
85101
driver = awscli.clidriver.create_clidriver()
86102
session = driver.session

‎tests/integration/customizations/s3/test_plugin.py‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from nose.plugins.attrib import attr
3535

3636
from awscli.testutils import unittest, get_stdout_encoding
37+
from awscli.testutils import skip_if_windows
3738
from awscli.testutils import aws as _aws
3839
from awscli.testutils import BaseS3CLICommand
3940
from tests.integration.customizations.s3 import create_bucket as _create_bucket
@@ -221,8 +222,7 @@ def test_cant_move_large_file_onto_itself(self):
221222

222223

223224
class TestRm(BaseS3CLICommand):
224-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
225-
'Newline in filename test not valid on windows.')
225+
@skip_if_windows('Newline in filename test not valid on windows.')
226226
# Windows won't let you do this. You'll get:
227227
# [Errno 22] invalid mode ('w') or filename:
228228
# 'c:\\windows\\temp\\tmp0fv8uu\\foo\r.txt'
@@ -341,8 +341,7 @@ def test_download_large_file(self):
341341
len(foo_contents.getvalue()))
342342

343343
@attr('slow')
344-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
345-
'SIGINT not supported on Windows.')
344+
@skip_if_windows('SIGINT not supported on Windows.')
346345
def test_download_ctrl_c_does_not_hang(self):
347346
bucket_name = self.create_bucket()
348347
foo_contents = six.BytesIO(b'abcd' * (1024 * 1024 * 20))
@@ -784,8 +783,7 @@ def test_no_exist(self):
784783
self.assertIn('The user-provided path %s does not exist.' %
785784
filename, p.stderr)
786785

787-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
788-
'Read permissions tests only supported on mac/linux')
786+
@skip_if_windows('Read permissions tests only supported on mac/linux')
789787
def test_no_read_access(self):
790788
if os.geteuid() == 0:
791789
self.skipTest('Cannot completely remove read access as root user.')
@@ -800,8 +798,7 @@ def test_no_read_access(self):
800798
self.assertIn('warning: Skipping file %s. File/Directory is '
801799
'not readable.' % filename, p.stderr)
802800

803-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
804-
'Special files only supported on mac/linux')
801+
@skip_if_windows('Special files only supported on mac/linux')
805802
def test_is_special_file(self):
806803
file_path = os.path.join(self.files.rootdir, 'foo')
807804
# Use socket for special file.
@@ -814,8 +811,7 @@ def test_is_special_file(self):
814811
"socket." % file_path), p.stderr)
815812

816813

817-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
818-
'Symlink tests only supported on mac/linux')
814+
@skip_if_windows('Symlink tests only supported on mac/linux')
819815
class TestSymlinks(BaseS3CLICommand):
820816
"""
821817
This class test the ability to follow or not follow symlinks.
@@ -1203,8 +1199,7 @@ def test_dryrun_download_large_file(self):
12031199
"argument was not obeyed.")
12041200

12051201

1206-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
1207-
'Memory tests only supported on mac/linux')
1202+
@skip_if_windows('Memory tests only supported on mac/linux')
12081203
class TestMemoryUtilization(BaseS3CLICommand):
12091204
# These tests verify the memory utilization and growth are what we expect.
12101205
def extra_setup(self):

‎tests/integration/test_cli.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import botocore.session
2121
from awscli.testutils import unittest, aws, BaseS3CLICommand
2222
from awscli.testutils import temporary_file
23+
from awscli.testutils import skip_if_windows
2324
from awscli.clidriver import create_clidriver
2425

2526

@@ -354,6 +355,7 @@ def test_error_msg_with_no_region_configured(self):
354355
p = aws('ec2 describe-instances', env_vars=environ)
355356
self.assertIn('must specify a region', p.stderr)
356357

358+
@skip_if_windows('Ctrl-C not supported on windows.')
357359
def test_ctrl_c_does_not_print_traceback(self):
358360
# Relying on the fact that this generally takes
359361
# more than 1 second to complete.

‎tests/unit/customizations/s3/test_filegenerator.py‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import platform
1515
from awscli.testutils import unittest, FileCreator, BaseAWSCommandParamsTest
16+
from awscli.testutils import skip_if_windows
1617
import stat
1718
import tempfile
1819
import shutil
@@ -29,8 +30,7 @@
2930
compare_files
3031

3132

32-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
33-
'Special files only supported on mac/linux')
33+
@skip_if_windows('Special files only supported on mac/linux')
3434
class TestIsSpecialFile(unittest.TestCase):
3535
def setUp(self):
3636
self.files = FileCreator()
@@ -158,8 +158,7 @@ def test_local_directory(self):
158158
compare_files(self, result_list[i], ref_list[i])
159159

160160

161-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
162-
'Symlink tests only supported on mac/linux')
161+
@skip_if_windows('Symlink tests only supported on mac/linux')
163162
class TestIgnoreFilesLocally(unittest.TestCase):
164163
"""
165164
This class tests the ability to ignore particular files. This includes
@@ -251,8 +250,7 @@ def test_no_read_access(self):
251250
("warning: Skipping file %s. File/Directory is "
252251
"not readable." % full_path))
253252

254-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
255-
'Special files only supported on mac/linux')
253+
@skip_if_windows('Special files only supported on mac/linux')
256254
def test_is_special_file_warning(self):
257255
file_gen = FileGenerator(self.client, '', False)
258256
file_path = os.path.join(self.files.rootdir, 'foo')
@@ -268,8 +266,7 @@ def test_is_special_file_warning(self):
268266
"socket." % file_path))
269267

270268

271-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
272-
'Symlink tests only supported on mac/linux')
269+
@skip_if_windows('Symlink tests only supported on mac/linux')
273270
class TestSymlinksIgnoreFiles(unittest.TestCase):
274271
"""
275272
This class tests the ability to list out the correct local files

‎tests/unit/customizations/test_assumerole.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from botocore.exceptions import PartialCredentialsError
2222
from dateutil.tz import tzlocal
2323

24-
from awscli.testutils import unittest
24+
from awscli.testutils import unittest, skip_if_windows
2525
from awscli.customizations import assumerole
2626

2727

@@ -400,8 +400,7 @@ def test_key_error_raised_when_cache_key_does_not_exist(self):
400400
with self.assertRaises(KeyError):
401401
self.cache['foo']
402402

403-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
404-
'File permissions tests not supported on Windows.')
403+
@skip_if_windows('File permissions tests not supported on Windows.')
405404
def test_permissions_for_file_restricted(self):
406405
self.cache['mykey'] = {'foo': 'bar'}
407406
filename = os.path.join(self.tempdir, 'mykey.json')

‎tests/unit/customizations/test_configure.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from six import StringIO
2222

2323
from awscli.customizations import configure
24-
from awscli.testutils import unittest
24+
from awscli.testutils import unittest, skip_if_windows
2525

2626

2727
class PrecannedPrompter(object):
@@ -419,8 +419,7 @@ def test_config_file_does_not_exist(self):
419419
new_contents = f.read()
420420
self.assertEqual(new_contents, '[default]\nfoo = value\n')
421421

422-
@unittest.skipIf(sys.platform.lower().startswith('win'),
423-
"Test not valid on windows.")
422+
@skip_if_windows("Test not valid on windows.")
424423
def test_permissions_on_new_file(self):
425424
self.writer.update_config({'foo': 'value'}, self.config_filename)
426425
with open(self.config_filename, 'r') as f:

‎tests/unit/output/test_json_output.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from awscli.formatter import JSONFormatter
1919

2020
from awscli.testutils import BaseAWSCommandParamsTest, unittest
21+
from awscli.testutils import skip_if_windows
2122
from awscli.compat import get_stdout_text_writer
2223

2324

@@ -101,8 +102,7 @@ def test_unknown_output_type_from_env_var(self):
101102
self.environ['AWS_DEFAULT_OUTPUT'] = 'bad-output-type'
102103
self.run_cmd('iam list-users', expected_rc=255)
103104

104-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
105-
'Encoding tests only supported on mac/linux')
105+
@skip_if_windows('Encoding tests only supported on mac/linux')
106106
def test_json_prints_unicode_chars(self):
107107
self.parsed_response['Users'][1]['UserId'] = u'\u2713'
108108
output = self.run_cmd('iam list-users', expected_rc=0)[0]

‎tests/unit/test_help.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
from awscli.testutils import unittest, FileCreator
13+
from awscli.testutils import unittest, skip_if_windows, FileCreator
1414
import signal
1515
import platform
1616
import json
@@ -92,7 +92,7 @@ def test_pager_with_args(self):
9292
self.assertEqual(self.renderer.get_pager_cmdline(),
9393
pager_cmd.split())
9494

95-
@unittest.skipIf(sys.platform.startswith('win'), "requires posix system")
95+
@skip_if_windows('Requires posix system.')
9696
def test_no_groff_exists(self):
9797
renderer = FakePosixHelpRenderer()
9898
renderer.exists_on_path['groff'] = False
@@ -119,8 +119,7 @@ def test_can_page_output_on_windows(self):
119119
renderer.render('foo')
120120
self.assertEqual(renderer.popen_calls[-1][0], (['more'],))
121121

122-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
123-
"Ctrl-C not valid on windows.")
122+
@skip_if_windows("Ctrl-C not valid on windows.")
124123
def test_can_handle_ctrl_c(self):
125124
class CtrlCRenderer(FakePosixHelpRenderer):
126125
def _popen(self, *args, **kwargs):

‎tests/unit/test_paramfile.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import mock
1616
from awscli.compat import six
1717
from awscli.testutils import unittest, FileCreator
18+
from awscli.testutils import skip_if_windows
1819

1920
from awscli.paramfile import get_paramfile, ResourceLoadingError
2021

@@ -42,9 +43,8 @@ def test_binary_file(self):
4243
self.assertEqual(data, b'This is a test')
4344
self.assertIsInstance(data, six.binary_type)
4445

45-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
46-
'Binary content error only occurs on '
47-
'non-Windows platforms.')
46+
@skip_if_windows('Binary content error only occurs '
47+
'on non-Windows platforms.')
4848
def test_cannot_load_text_file(self):
4949
contents = b'\xbfX\xac\xbe'
5050
filename = self.files.create_file('foo', contents, mode='wb')

‎tests/unit/test_utils.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import platform
1515
import os
1616

17-
from awscli.testutils import unittest
17+
from awscli.testutils import unittest, skip_if_windows
1818
from awscli.utils import split_on_commas, ignore_ctrl_c
1919

2020

@@ -91,8 +91,7 @@ def test_end_bracket_in_value(self):
9191
['foo', 'bar=foo,*[biz]*,baz'])
9292

9393

94-
@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
95-
"Ctrl-C not valid on windows.")
94+
@skip_if_windows("Ctrl-C not supported on windows.")
9695
class TestIgnoreCtrlC(unittest.TestCase):
9796
def test_ctrl_c_is_ignored(self):
9897
with ignore_ctrl_c():

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL