test_utils.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"). You
  4. # may not use this file except in compliance with the License. A copy of
  5. # the License is located at
  6. #
  7. # http://aws.amazon.com/apache2.0/
  8. #
  9. # or in the "license" file accompanying this file. This file is
  10. # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  11. # ANY KIND, either express or implied. See the License for the specific
  12. # language governing permissions and limitations under the License.
  13. import os
  14. import shutil
  15. import socket
  16. import tempfile
  17. from s3transfer.utils import OSUtils
  18. from tests import skip_if_windows, unittest
  19. @skip_if_windows('Windows does not support UNIX special files')
  20. class TestOSUtilsSpecialFiles(unittest.TestCase):
  21. def setUp(self):
  22. self.tempdir = tempfile.mkdtemp()
  23. self.filename = os.path.join(self.tempdir, 'myfile')
  24. def tearDown(self):
  25. shutil.rmtree(self.tempdir)
  26. def test_character_device(self):
  27. self.assertTrue(OSUtils().is_special_file('/dev/null'))
  28. def test_fifo(self):
  29. os.mkfifo(self.filename)
  30. self.assertTrue(OSUtils().is_special_file(self.filename))
  31. def test_socket(self):
  32. sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  33. sock.bind(self.filename)
  34. self.assertTrue(OSUtils().is_special_file(self.filename))