def _create_paths(self): """Create the paths for the tests. The following structure will be created: self.basedir/ |-> self.testfile |-> dir0/ |-> file0 |-> link |-> dir1/ |-> file1 |-> dir11/ |-> dir2/ |-> file2 |-> dir3/ """ open_file(self.testfile, 'w').close() for i in xrange(3): dir_name = 'dir%i' % i dir_path = os.path.join(self.basedir, dir_name) make_dir(dir_path, recursive=True) file_name = 'file%i' % i file_path = os.path.join(dir_path, file_name) open_file(file_path, "w").close() make_link(os.path.devnull, os.path.join(self.basedir, 'dir0', 'link')) make_dir(os.path.join(self.basedir, 'dir1', 'dir11')) make_dir(os.path.join(self.basedir, 'dir3'), recursive=True)
def _assert_read_link(self, target): """Assert if the target path of the link is correct.""" destination = os.path.join(self.basedir, target) make_link(self.testfile, destination) target = read_link(destination) self.assertEqual(self.testfile, target)
def test_make_link(self): """The link is properly made.""" destination = os.path.join(self.basedir, 'destination') make_link(self.testfile, destination) self.assertTrue(is_link(destination)) self.assertEqual(os.path.normcase(self.testfile), os.path.normcase(read_link(destination)))
def test_create_dirs_already_exists_symlink_too(self): """test that creating a Main instance works as expected.""" link = os.path.join(self.root, 'Shared With Me') make_link(self.shares, link) self.assertTrue(is_link(link)) self.assertTrue(path_exists(self.shares)) self.assertTrue(path_exists(self.root)) main = self.build_main() # check that the shares link is actually a link self.assertTrue(is_link(main.shares_dir_link))
def create_shares_link(source, dest): """Create the shares symlink.""" result = False if not path_exists(dest): # remove the symlink if it's broken if is_link(dest) and read_link(dest) != source: remove_link(dest) if not is_link(dest): # only create the link if it does not exist make_link(source, dest) result = True return result
def test_path_exist_for_link_without_lnk_extension(self): """Test if the path of a link exist without the lnk extension.""" destination = os.path.join(self.basedir, 'destination') make_link(self.testfile, destination) self.assertTrue(path_exists(destination))