Skip to content

Commit e55ea53

Browse files
committed
Fix timestamp related s3 tests failing on MacOS
On MacOS the file timestamp can no longer be invalid. This means our tests that were checking for a warning by setting an invalid timestamp no longer emit such a warning on newer Macs. In one test it was specifically for invalid timestamps. This one is now skipped on MacOS since it is not a valid case to check for anymore. The other was a test to see if an error and a warning can be emitted at the same time. It was using an invalid timestamp incidentally to emit a warning. This test is run the same way on windows, and now skipped on posix systems. The test was duplicated for posix systems and uses an unreadable file to generate the warning.
1 parent 8b21241 commit e55ea53

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

awscli/testutils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ def decorator(func):
9797
return decorator
9898

9999

100+
def skip_if_macos(reason):
101+
"""Decorator to skip tests that should not be run on MacOS.
102+
103+
Example usage:
104+
105+
@skip_if_macos("Not valid")
106+
def test_some_non_macos_stuff(self):
107+
self.assertEqual(...)
108+
109+
"""
110+
def decorator(func):
111+
return unittest.skipIf(
112+
platform.system() in ['Darwin'], reason)(func)
113+
return decorator
114+
115+
100116
def set_invalid_utime(path):
101117
"""Helper function to set an invalid last modified time"""
102118
try:

tests/functional/s3/test_cp_command.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from awscli.testutils import BaseAWSCommandParamsTest
1818
from awscli.testutils import capture_input, set_invalid_utime
19+
from awscli.testutils import skip_if_windows, skip_if_macos
1920
from awscli.compat import six
2021
from tests.functional.s3 import BaseS3TransferCommandTest
2122

@@ -615,7 +616,29 @@ def test_upload_unicode_path(self):
615616
progress_message = 'Completed 10 Bytes'
616617
self.assertIn(progress_message, stdout)
617618

618-
def test_cp_with_error_and_warning(self):
619+
620+
@skip_if_windows("Unreadable file is hard to make on windows")
621+
def test_cp_with_error_and_warning_unreadable_file(self):
622+
command = "s3 cp --recursive %s s3://bucket/"
623+
self.parsed_responses = [{
624+
'Error': {
625+
'Code': 'NoSuchBucket',
626+
'Message': 'The specified bucket does not exist',
627+
'BucketName': 'bucket'
628+
}
629+
}]
630+
self.http_response.status_code = 404
631+
632+
unreadable_path = self.files.create_file('foo.txt', 'foo')
633+
self.files.create_file('bar.txt', 'bar')
634+
os.chmod(unreadable_path, 0o222)
635+
_, stderr, rc = self.run_cmd(command % self.files.rootdir, expected_rc=1)
636+
self.assertIn('upload failed', stderr)
637+
self.assertIn('warning: Skipping file', stderr)
638+
self.assertIn('File/Directory is not readable.', stderr)
639+
640+
@skip_if_macos("On MacOS we cannot create an invalid timestamp.")
641+
def test_cp_with_error_and_warning_invalid_timestamp(self):
619642
command = "s3 cp %s s3://bucket/foo.txt"
620643
self.parsed_responses = [{
621644
'Error': {

tests/functional/s3/test_sync_command.py

Lines changed: 2 additions & 1 deletion
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 set_invalid_utime
13+
from awscli.testutils import set_invalid_utime, skip_if_macos
1414
from mock import patch
1515
import os
1616

@@ -123,6 +123,7 @@ def test_turn_off_glacier_warnings(self):
123123
self.assertEqual(self.operations_called[0][0].name, 'ListObjectsV2')
124124
self.assertEqual('', stderr)
125125

126+
@skip_if_macos("Timestamps can't be invalid on macos")
126127
def test_warning_on_invalid_timestamp(self):
127128
full_path = self.files.create_file('foo.txt', 'mycontent')
128129

0 commit comments

Comments
 (0)