1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
11 from profile_creators
import profile_generator
14 class ProfileGeneratorUnitTest(unittest
.TestCase
):
16 self
.test_directory
= tempfile
.mkdtemp()
17 super(ProfileGeneratorUnitTest
, self
).setUp()
19 def _CreateFunkyFilesAndOnePlainFile(self
, sandbox_directory
):
20 """Create several special files and one plain file in |sandbox_directory|.
22 if os
.path
.exists(sandbox_directory
):
23 shutil
.rmtree(sandbox_directory
)
25 os
.mkdir(sandbox_directory
)
28 plain_filename
= os
.path
.join(sandbox_directory
, 'plain_file')
29 open(plain_filename
, 'a').close()
32 directory_filename
= os
.path
.join(sandbox_directory
, 'directory')
33 os
.mkdir(directory_filename
)
35 if getattr(os
, 'symlink', None): # Symlinks not supported on Windows.
37 symlink_filename
= os
.path
.join(sandbox_directory
, 'symlink')
38 os
.symlink(plain_filename
, symlink_filename
)
40 # Make a broken symlink.
41 nonexistant_filename
= os
.path
.join(sandbox_directory
, 'i_dont_exist')
42 broken_symlink_filename
= os
.path
.join(sandbox_directory
,
44 os
.symlink(nonexistant_filename
, broken_symlink_filename
)
46 # Make a named socket.
47 if getattr(socket
, 'AF_UNIX', None): # Windows doesn't support these.
48 socket_filename
= os
.path
.join(sandbox_directory
, 'named_socket')
49 the_socket
= socket
.socket(socket
.AF_UNIX
, socket
.SOCK_STREAM
)
50 the_socket
.bind(socket_filename
)
52 def testIsPseudoFile(self
):
53 sandbox_dir
= os
.path
.join(self
.test_directory
, "sandbox")
54 self
._CreateFunkyFilesAndOnePlainFile
(sandbox_dir
)
56 # If we can copy the directory, we're golden!
57 sandbox_dir_copy
= os
.path
.join(self
.test_directory
, "sandbox_copy")
58 # pylint: disable=W0212
59 shutil
.copytree(sandbox_dir
, sandbox_dir_copy
,
60 ignore
=profile_generator
._IsPseudoFile
)
62 # Check that only the directory and plain file got copied.
63 dir_contents
= os
.listdir(sandbox_dir_copy
)
65 self
.assertEqual(['directory', 'plain_file'], dir_contents
)
68 shutil
.rmtree(self
.test_directory
)