test_utils.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 __tests__ import unittest
  18. from __tests__ import skip_if_windows
  19. from s3transfer.utils import OSUtils
  20. @skip_if_windows('Windows does not support UNIX special files')
  21. class TestOSUtilsSpecialFiles(unittest.TestCase):
  22. def setUp(self):
  23. self.tempdir = tempfile.mkdtemp()
  24. self.filename = os.path.join(self.tempdir, 'myfile')
  25. def tearDown(self):
  26. shutil.rmtree(self.tempdir)
  27. def test_character_device(self):
  28. self.assertTrue(OSUtils().is_special_file('/dev/null'))
  29. def test_fifo(self):
  30. os.mkfifo(self.filename)
  31. self.assertTrue(OSUtils().is_special_file(self.filename))
  32. def test_socket(self):
  33. sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  34. sock.bind(self.filename)
  35. self.assertTrue(OSUtils().is_special_file(self.filename))