예제 #1
0
    def test_delete(self):
        """ folder deletion """

        f = File("data/sub")
        self.assertFalse(f.exists)

        # Create the folder.
        f.create_folder()
        self.assertTrue(f.exists)
        self.assertRaises(ValueError, f.create_folder)

        self.assertEqual(len(f.children), 0)
        self.assertEqual(f.ext, "")
        self.assertFalse(f.is_file)
        self.assertTrue(f.is_folder)
        self.assertEqual(f.mime_type, "content/unknown")
        self.assertEqual(f.name, "sub")
        self.assertEqual(f.path, "data/sub")

        # Delete it.
        f.delete()
        self.assertFalse(f.exists)

        # Attempt to delete a non-existet folder (should do nothing).
        f = File("data/bogus")
        self.assertFalse(f.exists)

        f.delete()
        self.assertFalse(f.exists)
    def test_delete(self):
        """ folder deletion """

        f = File('data/sub')
        self.assertEqual(f.exists, False)

        # Create the folder.
        f.create_folder()
        self.assertEqual(f.exists, True)
        self.assertRaises(ValueError, f.create_folder)

        self.assertEqual(len(f.children), 0)
        self.assertEqual(f.ext, '')
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, True)
        self.assertEqual(f.mime_type, 'content/unknown')
        self.assertEqual(f.name, 'sub')
        self.assertEqual(f.path, 'data/sub')

        # Delete it.
        f.delete()
        self.assertEqual(f.exists, False)

        # Attempt to delete a non-existet folder (should do nothing).
        f = File('data/bogus')
        self.assertEqual(f.exists, False)

        f.delete()
        self.assertEqual(f.exists, False)

        return
    def test_delete(self):
        """ file deletion """

        content = 'print "Hello World!"\n'

        f = File('data/foo.txt')
        self.assertEqual(f.exists, False)

        # Create the file.
        f.create_file(content)
        self.assertEqual(f.exists, True)
        self.assertRaises(ValueError, f.create_file, content)

        self.assertEqual(f.children, None)
        self.assertEqual(f.ext, '.txt')
        self.assertEqual(f.is_file, True)
        self.assertEqual(f.is_folder, False)
        self.assertEqual(f.mime_type, 'text/plain')
        self.assertEqual(f.name, 'foo')
        self.assertEqual(f.path, 'data/foo.txt')

        # Delete it.
        f.delete()
        self.assertEqual(f.exists, False)

        # Attempt to delete a non-existet file (should do nothing).
        f = File('data/bogus.txt')
        self.assertEqual(f.exists, False)

        f.delete()
        self.assertEqual(f.exists, False)

        return
예제 #4
0
    def test_delete(self):
        """ file deletion """

        content = 'print("Hello World!")\n'

        f = File("data/foo.txt")
        self.assertFalse(f.exists)

        # Create the file.
        f.create_file(content)
        self.assertTrue(f.exists)
        self.assertRaises(ValueError, f.create_file, content)

        self.assertIsNone(f.children)
        self.assertEqual(f.ext, ".txt")
        self.assertTrue(f.is_file)
        self.assertFalse(f.is_folder)
        self.assertEqual(f.mime_type, "text/plain")
        self.assertEqual(f.name, "foo")
        self.assertEqual(f.path, "data/foo.txt")

        # Delete it.
        f.delete()
        self.assertFalse(f.exists)

        # Attempt to delete a non-existet file (should do nothing).
        f = File("data/bogus.txt")
        self.assertFalse(f.exists)

        f.delete()
        self.assertFalse(f.exists)
예제 #5
0
    def test_delete(self):
        """ folder deletion """

        f = File('data/sub')
        self.assertEqual(f.exists, False)

        # Create the folder.
        f.create_folder()
        self.assertEqual(f.exists, True)
        self.failUnlessRaises(ValueError, f.create_folder)

        self.assertEqual(len(f.children), 0)
        self.assertEqual(f.ext, '')
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, True)
        self.assertEqual(f.mime_type, 'content/unknown')
        self.assertEqual(f.name, 'sub')
        self.assertEqual(f.path, 'data/sub')

        # Delete it.
        f.delete()
        self.assertEqual(f.exists, False)

        # Attempt to delete a non-existet folder (should do nothing).
        f = File('data/bogus')
        self.assertEqual(f.exists, False)

        f.delete()
        self.assertEqual(f.exists, False)

        return
예제 #6
0
    def test_delete(self):
        """ file deletion """

        content = 'print "Hello World!"\n'

        f = File("data/foo.txt")
        self.assertEqual(f.exists, False)

        # Create the file.
        f.create_file(content)
        self.assertEqual(f.exists, True)
        self.failUnlessRaises(ValueError, f.create_file, content)

        self.assertEqual(f.children, None)
        self.assertEqual(f.ext, ".txt")
        self.assertEqual(f.is_file, True)
        self.assertEqual(f.is_folder, False)
        self.assertEqual(f.mime_type, "text/plain")
        self.assertEqual(f.name, "foo")
        self.assertEqual(f.path, "data/foo.txt")

        # Delete it.
        f.delete()
        self.assertEqual(f.exists, False)

        # Attempt to delete a non-existet file (should do nothing).
        f = File("data/bogus.txt")
        self.assertEqual(f.exists, False)

        f.delete()
        self.assertEqual(f.exists, False)

        return
예제 #7
0
    def test_properties(self):
        """ file properties """

        # Properties of a non-existent file.
        f = File('data/bogus.xx')

        self.assert_(os.path.abspath(os.path.curdir) in f.absolute_path)
        self.assertEqual(f.children, None)
        self.assertEqual(f.ext, '.xx')
        self.assertEqual(f.exists, False)
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, False)
        self.assertEqual(f.is_package, False)
        self.assertEqual(f.is_readonly, False)
        self.assertEqual(f.mime_type, 'content/unknown')
        self.assertEqual(f.name, 'bogus')
        self.assertEqual(f.parent.path, 'data')
        self.assertEqual(f.path, 'data/bogus.xx')
        self.assert_(os.path.abspath(os.path.curdir) in f.url)
        self.assertEqual(str(f), 'File(%s)' % f.path)

        # Properties of an existing file.
        f = File('data/foo.py')
        f.create_file()

        self.assert_(os.path.abspath(os.path.curdir) in f.absolute_path)
        self.assertEqual(f.children, None)
        self.assertEqual(f.ext, '.py')
        self.assertEqual(f.exists, True)
        self.assertEqual(f.is_file, True)
        self.assertEqual(f.is_folder, False)
        self.assertEqual(f.is_package, False)
        self.assertEqual(f.is_readonly, False)
        self.assertEqual(f.mime_type, 'text/x-python')
        self.assertEqual(f.name, 'foo')
        self.assertEqual(f.parent.path, 'data')
        self.assertEqual(f.path, 'data/foo.py')
        self.assert_(os.path.abspath(os.path.curdir) in f.url)

        # Make it readonly.
        os.chmod(f.path, stat.S_IRUSR)
        self.assertEqual(f.is_readonly, True)

        # And then make it NOT readonly so that we can delete it at the end of
        # the test!
        os.chmod(f.path, stat.S_IRUSR | stat.S_IWUSR)
        self.assertEqual(f.is_readonly, False)

        return
예제 #8
0
    def test_properties(self):
        """ file properties """

        # Properties of a non-existent file.
        f = File("data/bogus.xx")

        self.assert_(os.path.abspath(os.path.curdir) in f.absolute_path)
        self.assertEqual(f.children, None)
        self.assertEqual(f.ext, ".xx")
        self.assertEqual(f.exists, False)
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, False)
        self.assertEqual(f.is_package, False)
        self.assertEqual(f.is_readonly, False)
        self.assertEqual(f.mime_type, "content/unknown")
        self.assertEqual(f.name, "bogus")
        self.assertEqual(f.parent.path, "data")
        self.assertEqual(f.path, "data/bogus.xx")
        self.assert_(os.path.abspath(os.path.curdir) in f.url)
        self.assertEqual(str(f), "File(%s)" % f.path)

        # Properties of an existing file.
        f = File("data/foo.txt")
        f.create_file()

        self.assert_(os.path.abspath(os.path.curdir) in f.absolute_path)
        self.assertEqual(f.children, None)
        self.assertEqual(f.ext, ".txt")
        self.assertEqual(f.exists, True)
        self.assertEqual(f.is_file, True)
        self.assertEqual(f.is_folder, False)
        self.assertEqual(f.is_package, False)
        self.assertEqual(f.is_readonly, False)
        self.assertEqual(f.mime_type, "text/plain")
        self.assertEqual(f.name, "foo")
        self.assertEqual(f.parent.path, "data")
        self.assertEqual(f.path, "data/foo.txt")
        self.assert_(os.path.abspath(os.path.curdir) in f.url)

        # Make it readonly.
        os.chmod(f.path, stat.S_IRUSR)
        self.assertEqual(f.is_readonly, True)

        # And then make it NOT readonly so that we can delete it at the end of
        # the test!
        os.chmod(f.path, stat.S_IRUSR | stat.S_IWUSR)
        self.assertEqual(f.is_readonly, False)

        return
예제 #9
0
    def test_create_file(self):
        """ file creation """

        content = 'print("Hello World!")\n'

        f = File("data/foo.txt")
        self.assertFalse(f.exists)

        # Create the file.
        f.create_file(content)
        self.assertTrue(f.exists)
        with open(f.path) as file:
            self.assertEqual(file.read(), content)

        # Try to create it again.
        self.assertRaises(ValueError, f.create_file, content)
    def _harvest_plugins_in_package(self, package_name, package_dirname):
        """ Harvest plugins found in the given package. """

        # If the package contains a 'plugins.py' module, then we import it and
        # look for a callable 'get_plugins' that takes no arguments and returns
        # a list of plugins (i.e. instances that implement 'IPlugin'!).
        plugins_module = self._get_plugins_module(package_name)
        if plugins_module is not None:
            factory = getattr(plugins_module, 'get_plugins', None)
            if factory is not None:
                plugins = factory()

        # Otherwise, look for any modules in the form 'xxx_plugin.py' and
        # see if they contain a callable in the form 'XXXPlugin' and if they
        # do, call it with no arguments to get a plugin!
        else:
            plugins = []
            logger.debug('Looking for plugins in %s' % package_dirname)
            for child in File(package_dirname).children or []:
                if child.ext == '.py' and child.name.endswith('_plugin'):
                    module = __import__(package_name + '.' + child.name,
                                        fromlist=[child.name])

                    atoms = child.name.split('_')
                    capitalized = [atom.capitalize() for atom in atoms]
                    factory_name = ''.join(capitalized)

                    factory = getattr(module, factory_name, None)
                    if factory is not None:
                        plugins.append(factory())

        return plugins
예제 #11
0
    def test_create_folder(self):
        """ folder creation """

        f = File("data/sub")
        self.assertFalse(f.exists)

        # Create the folder.
        f.create_folder()
        self.assertTrue(f.exists)

        parent = File("data")
        self.assertEqual(len(parent.children), 1)
        self.assertEqual(parent.children[0].path, join("data", "sub"))

        # Try to create it again.
        self.assertRaises(ValueError, f.create_folder)
    def test_lookup(self):
        """ pyfs context lookup """

        # Convenience.
        context = self.context
        sub = self.context.lookup('sub')

        # Make sure that the sub-context is empty.
        self.assertEqual(len(sub.list_bindings('')), 0)

        # Bind a file object.
        f = File(os.path.join(sub.path, 'foo.py'))
        #f.create_file('print "foo!"\n')

        context.bind('sub/foo.py', f)
        self.assertEqual(len(sub.list_bindings('')), 1)

        # Look it up.
        self.assertEqual(context.lookup('sub/foo.py').path, f.path)

        # Bind a Python object.
        context.bind('sub/a', 1)
        self.assertEqual(len(sub.list_bindings('')), 2)

        # Look it up.
        self.assertEqual(context.lookup('sub/a'), 1)

        # Looking up the Empty name returns the context itself.
        self.assertEqual(context.lookup(''), context)

        # Non-existent name.
        self.assertRaises(NameNotFoundError, context.lookup, 'sub/b')

        return
예제 #13
0
    def OnData(self, x, y, default_drag_result):
        """ Called when OnDrop returns True. """

        # First, if we have a source in the clipboard and the source
        # doesn't allow moves then change the default to copy
        if clipboard.drop_source is not None and \
           not clipboard.drop_source.allow_move:
            default_drag_result = wx.DragCopy
        elif clipboard.drop_source is None:
            # This means we might be receiving a file; try to import
            # the right packages to nicely handle a file drop.  If those
            # packages can't be imported, then just pass through.
            if self.GetData():
                try:
                    from apptools.io import File
                    from apptools.naming.api import Binding

                    names = self.file_data.GetFilenames()
                    files = []
                    bindings = []
                    for name in names:
                        f = File(name)
                        files.append(f)
                        bindings.append(Binding(name = name, obj = f))
                    clipboard.data = files
                    clipboard.node = bindings
                except ImportError:
                    pass

        # Pass the object on the clipboard it to the handler.
        #
        # fixme: We allow 'wx_dropped_on' and 'on_drop' because both Dave
        # and Martin want different things! Unify!
        if hasattr(self.handler, 'wx_dropped_on'):
            drag_result = self.handler.wx_dropped_on(
                x, y, clipboard.data, default_drag_result
            )

        elif hasattr(self.handler, 'on_drop'):
            drag_result = self.handler.on_drop(
                x, y, clipboard.data, default_drag_result
            )

        else:
            self.handler(x, y, clipboard.data)
            drag_result = default_drag_result

        # Let the source of the drag/drop know that the operation is complete.
        drop_source = clipboard.drop_source
        if drop_source is not None:
            drop_source.on_dropped(drag_result)

        # Clean out the drop source!
        clipboard.drop_source = None

        # The return value tells the source what to do with the original data
        # (move, copy, etc.).  In this case we just return the suggested value
        # given to us.
        return default_drag_result
예제 #14
0
    def test_create_folders(self):
        """ nested folder creation """

        f = File("data/sub/foo")
        self.assertFalse(f.exists)

        # Attempt to create the folder with 'create_folder' which requires
        # that all intermediate folders exist.
        self.assertRaises(OSError, f.create_folder)

        # Create the folder.
        f.create_folders()
        self.assertTrue(f.exists)
        self.assertTrue(File("data/sub").exists)

        # Try to create it again.
        self.assertRaises(ValueError, f.create_folders)
예제 #15
0
    def test_create_file(self):
        """ file creation """

        content = 'print "Hello World!"\n'

        f = File("data/foo.txt")
        self.assertEqual(f.exists, False)

        # Create the file.
        f.create_file(content)
        self.assertEqual(f.exists, True)
        self.assertEqual(file(f.path).read(), content)

        # Try to create it again.
        self.failUnlessRaises(ValueError, f.create_file, content)

        return
    def test_create_file(self):
        """ file creation """

        content = 'print "Hello World!"\n'

        f = File('data/foo.txt')
        self.assertEqual(f.exists, False)

        # Create the file.
        f.create_file(content)
        self.assertEqual(f.exists, True)
        self.assertEqual(open(f.path).read(), content)

        # Try to create it again.
        self.assertRaises(ValueError, f.create_file, content)

        return
예제 #17
0
    def test_create_folder(self):
        """ folder creation """

        f = File('data/sub')
        self.assertEqual(f.exists, False)

        # Create the folder.
        f.create_folder()
        self.assertEqual(f.exists, True)

        parent = File('data')
        self.assertEqual(len(parent.children), 1)
        self.assertEqual(parent.children[0].path, join('data', 'sub'))

        # Try to create it again.
        self.failUnlessRaises(ValueError, f.create_folder)

        return
    def test_create_folder(self):
        """ folder creation """

        f = File('data/sub')
        self.assertEqual(f.exists, False)

        # Create the folder.
        f.create_folder()
        self.assertEqual(f.exists, True)

        parent = File('data')
        self.assertEqual(len(parent.children), 1)
        self.assertEqual(parent.children[0].path, join('data', 'sub'))

        # Try to create it again.
        self.assertRaises(ValueError, f.create_folder)

        return
    def test_create_folders(self):
        """ nested folder creation """

        f = File('data/sub/foo')
        self.assertEqual(f.exists, False)

        # Attempt to create the folder with 'create_folder' which requires
        # that all intermediate folders exist.
        self.assertRaises(OSError, f.create_folder)

        # Create the folder.
        f.create_folders()
        self.assertEqual(f.exists, True)
        self.assertEqual(File('data/sub').exists, True)

        # Try to create it again.
        self.assertRaises(ValueError, f.create_folders)

        return
예제 #20
0
    def test_create_folders(self):
        """ nested folder creation """

        f = File('data/sub/foo')
        self.assertEqual(f.exists, False)

        # Attempt to create the folder with 'create_folder' which requires
        # that all intermediate folders exist.
        self.failUnlessRaises(OSError, f.create_folder)

        # Create the folder.
        f.create_folders()
        self.assertEqual(f.exists, True)
        self.assertEqual(File('data/sub').exists, True)

        # Try to create it again.
        self.failUnlessRaises(ValueError, f.create_folders)

        return
    def _harvest_plugins_in_packages(self):
        """ Harvest plugins found in packages on the plugin path. """

        plugins = []
        for dirname in self.plugin_path:
            for child in File(dirname).children or []:
                if child.is_package:
                    plugins.extend(
                        self._harvest_plugins_in_package(
                            child.name, child.path))

        return plugins
    def test_bind(self):
        """ pyfs context bind """

        # Convenience.
        context = self.context
        sub = self.context.lookup('sub')

        # Make sure that the sub-context is empty.
        self.assertEqual(len(sub.list_bindings('')), 0)

        # Empty name.
        self.assertRaises(InvalidNameError, context.bind, '', 1)

        # Bind a local file object.
        f = File(os.path.join(sub.path, 'foo.py'))
        #f.create_file('print "foo!"\n')

        context.bind('sub/foo.py', f)
        self.assertEqual(len(sub.list_bindings('')), 1)

        # Bind a reference to a non-local file.
        f = File('/tmp')
        context.bind('sub/tmp', f)
        self.assertEqual(len(sub.list_bindings('')), 2)
        self.assertEqual(context.lookup('sub/tmp').path, f.path)

        # Bind a reference to a non-local context.
        f = PyFSContext(path='other')
        context.bind('sub/other', f)
        self.assertEqual(len(sub.list_bindings('')), 3)
        self.assertTrue(f.path in context.lookup('sub/other').path)

        # Bind a Python object.
        context.bind('sub/a', 1)
        self.assertEqual(len(sub.list_bindings('')), 4)

        # Try to bind it again.
        self.assertRaises(NameAlreadyBoundError, context.bind, 'sub/a', 1)

        return
예제 #23
0
    def test_bind(self):
        """ pyfs context bind """

        # Convenience.
        context = self.context
        sub = self.context.lookup("sub")

        # Make sure that the sub-context is empty.
        self.assertEqual(len(sub.list_bindings("")), 0)

        # Empty name.
        self.assertRaises(InvalidNameError, context.bind, "", 1)

        # Bind a local file object.
        f = File(os.path.join(sub.path, "foo.py"))
        # f.create_file('print("foo!")\n')

        context.bind("sub/foo.py", f)
        self.assertEqual(len(sub.list_bindings("")), 1)

        # Bind a reference to a non-local file.
        f = File("/tmp")
        context.bind("sub/tmp", f)
        self.assertEqual(len(sub.list_bindings("")), 2)
        self.assertEqual(context.lookup("sub/tmp").path, f.path)

        # Bind a reference to a non-local context.
        f = PyFSContext(path="other")
        context.bind("sub/other", f)
        self.assertEqual(len(sub.list_bindings("")), 3)
        self.assertIn(f.path, context.lookup("sub/other").path)

        # Bind a Python object.
        context.bind("sub/a", 1)
        self.assertEqual(len(sub.list_bindings("")), 4)

        # Try to bind it again.
        self.assertRaises(NameAlreadyBoundError, context.bind, "sub/a", 1)
예제 #24
0
    def test_copy(self):
        """ file copy """

        content = 'print "Hello World!"\n'

        f = File("data/foo.txt")
        self.assertEqual(f.exists, False)

        # Create the file.
        f.create_file(content)
        self.assertEqual(f.exists, True)
        self.failUnlessRaises(ValueError, f.create_file, content)

        self.assertEqual(f.children, None)
        self.assertEqual(f.ext, ".txt")
        self.assertEqual(f.is_file, True)
        self.assertEqual(f.is_folder, False)
        self.assertEqual(f.mime_type, "text/plain")
        self.assertEqual(f.name, "foo")
        self.assertEqual(f.path, "data/foo.txt")

        # Copy the file.
        g = File("data/bar.txt")
        self.assertEqual(g.exists, False)

        f.copy(g)
        self.assertEqual(g.exists, True)

        self.assertEqual(g.children, None)
        self.assertEqual(g.ext, ".txt")
        self.assertEqual(g.is_file, True)
        self.assertEqual(g.is_folder, False)
        self.assertEqual(g.mime_type, "text/plain")
        self.assertEqual(g.name, "bar")
        self.assertEqual(g.path, "data/bar.txt")

        # Attempt to copy a non-existent file (should do nothing).
        f = File("data/bogus.xx")
        self.assertEqual(f.exists, False)

        g = File("data/bogus_copy.txt")
        self.assertEqual(g.exists, False)

        f.copy(g)
        self.assertEqual(g.exists, False)

        return
예제 #25
0
    def test_copy(self):
        """ folder copy """

        f = File('data/sub')
        self.assertEqual(f.exists, False)

        # Create the folder.
        f.create_folder()
        self.assertEqual(f.exists, True)
        self.failUnlessRaises(ValueError, f.create_folder)

        self.assertEqual(len(f.children), 0)
        self.assertEqual(f.ext, '')
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, True)
        self.assertEqual(f.mime_type, 'content/unknown')
        self.assertEqual(f.name, 'sub')
        self.assertEqual(f.path, 'data/sub')

        # Copy the folder.
        g = File('data/copy')
        self.assertEqual(g.exists, False)

        f.copy(g)
        self.assertEqual(g.exists, True)

        self.assertEqual(len(g.children), 0)
        self.assertEqual(g.ext, '')
        self.assertEqual(g.is_file, False)
        self.assertEqual(g.is_folder, True)
        self.assertEqual(g.mime_type, 'content/unknown')
        self.assertEqual(g.name, 'copy')
        self.assertEqual(g.path, 'data/copy')

        # Attempt to copy a non-existent folder (should do nothing).
        f = File('data/bogus')
        self.assertEqual(f.exists, False)

        g = File('data/bogus_copy')
        self.assertEqual(g.exists, False)

        f.copy(g)
        self.assertEqual(g.exists, False)

        return
    def test_properties(self):
        """ file properties """

        # Properties of a non-existent file.
        f = File('data/bogus.xx')

        self.assertTrue(os.path.abspath(os.path.curdir) in f.absolute_path)
        self.assertEqual(f.children, None)
        self.assertEqual(f.ext, '.xx')
        self.assertEqual(f.exists, False)
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, False)
        self.assertEqual(f.is_package, False)
        self.assertEqual(f.is_readonly, False)
        self.assertEqual(f.mime_type, 'content/unknown')
        self.assertEqual(f.name, 'bogus')
        self.assertEqual(f.parent.path, 'data')
        self.assertEqual(f.path, 'data/bogus.xx')
        self.assertTrue(os.path.abspath(os.path.curdir) in f.url)
        self.assertEqual(str(f), 'File(%s)' % f.path)

        # Properties of an existing file.
        f = File('data/foo.txt')
        f.create_file()

        self.assertTrue(os.path.abspath(os.path.curdir) in f.absolute_path)
        self.assertEqual(f.children, None)
        self.assertEqual(f.ext, '.txt')
        self.assertEqual(f.exists, True)
        self.assertEqual(f.is_file, True)
        self.assertEqual(f.is_folder, False)
        self.assertEqual(f.is_package, False)
        self.assertEqual(f.is_readonly, False)
        self.assertEqual(f.mime_type, 'text/plain')
        self.assertEqual(f.name, 'foo')
        self.assertEqual(f.parent.path, 'data')
        self.assertEqual(f.path, 'data/foo.txt')
        self.assertTrue(os.path.abspath(os.path.curdir) in f.url)

        # Make it readonly.
        os.chmod(f.path, stat.S_IRUSR)
        self.assertEqual(f.is_readonly, True)

        # And then make it NOT readonly so that we can delete it at the end of
        # the test!
        os.chmod(f.path, stat.S_IRUSR | stat.S_IWUSR)
        self.assertEqual(f.is_readonly, False)

        return
예제 #27
0
    def test_properties(self):
        """ file properties """

        # Properties of a non-existent file.
        f = File("data/bogus.xx")

        self.assertIn(os.path.abspath(os.path.curdir), f.absolute_path)
        self.assertIsNone(f.children)
        self.assertEqual(f.ext, ".xx")
        self.assertFalse(f.exists)
        self.assertFalse(f.is_file)
        self.assertFalse(f.is_folder)
        self.assertFalse(f.is_package)
        self.assertFalse(f.is_readonly)
        self.assertEqual(f.mime_type, "content/unknown")
        self.assertEqual(f.name, "bogus")
        self.assertEqual(f.parent.path, "data")
        self.assertEqual(f.path, "data/bogus.xx")
        self.assertIn(os.path.abspath(os.path.curdir), f.url)
        self.assertEqual(str(f), "File(%s)" % f.path)

        # Properties of an existing file.
        f = File("data/foo.txt")
        f.create_file()

        self.assertIn(os.path.abspath(os.path.curdir), f.absolute_path)
        self.assertIsNone(f.children)
        self.assertEqual(f.ext, ".txt")
        self.assertTrue(f.exists)
        self.assertTrue(f.is_file)
        self.assertFalse(f.is_folder)
        self.assertFalse(f.is_package)
        self.assertFalse(f.is_readonly)
        self.assertEqual(f.mime_type, "text/plain")
        self.assertEqual(f.name, "foo")
        self.assertEqual(f.parent.path, "data")
        self.assertEqual(f.path, "data/foo.txt")
        self.assertIn(os.path.abspath(os.path.curdir), f.url)

        # Make it readonly.
        os.chmod(f.path, stat.S_IRUSR)
        self.assertTrue(f.is_readonly)

        # And then make it NOT readonly so that we can delete it at the end of
        # the test!
        os.chmod(f.path, stat.S_IRUSR | stat.S_IWUSR)
        self.assertFalse(f.is_readonly)
예제 #28
0
    def test_properties(self):
        """ folder properties """

        # Properties of a non-existent folder.
        f = File("data/bogus")

        self.assertIn(os.path.abspath(os.path.curdir), f.absolute_path)
        self.assertIsNone(f.children)
        self.assertEqual(f.ext, "")
        self.assertFalse(f.exists)
        self.assertFalse(f.is_file)
        self.assertFalse(f.is_folder)
        self.assertFalse(f.is_package)
        self.assertFalse(f.is_readonly)
        self.assertEqual(f.mime_type, "content/unknown")
        self.assertEqual(f.name, "bogus")
        self.assertEqual(f.parent.path, "data")
        self.assertEqual(f.path, "data/bogus")
        self.assertIn(os.path.abspath(os.path.curdir), f.url)
        self.assertEqual(str(f), "File(%s)" % f.path)

        # Properties of an existing folder.
        f = File("data/sub")
        f.create_folder()

        self.assertIn(os.path.abspath(os.path.curdir), f.absolute_path)
        self.assertEqual(len(f.children), 0)
        self.assertEqual(f.ext, "")
        self.assertTrue(f.exists)
        self.assertFalse(f.is_file)
        self.assertTrue(f.is_folder)
        self.assertFalse(f.is_package)
        self.assertFalse(f.is_readonly)
        self.assertEqual(f.mime_type, "content/unknown")
        self.assertEqual(f.name, "sub")
        self.assertEqual(f.parent.path, "data")
        self.assertEqual(f.path, "data/sub")
        self.assertIn(os.path.abspath(os.path.curdir), f.url)

        # Make it readonly.
        os.chmod(f.path, stat.S_IRUSR)
        self.assertTrue(f.is_readonly)

        # And then make it NOT readonly so that we can delete it at the end of
        # the test!
        os.chmod(f.path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
        self.assertFalse(f.is_readonly)

        # Properties of a Python package folder.
        f = File("data/package")
        f.create_folder()

        init = File("data/package/__init__.py")
        init.create_file()

        self.assertIn(os.path.abspath(os.path.curdir), f.absolute_path)
        self.assertEqual(len(f.children), 1)
        self.assertEqual(f.ext, "")
        self.assertTrue(f.exists)
        self.assertFalse(f.is_file)
        self.assertTrue(f.is_folder)
        self.assertTrue(f.is_package)
        self.assertFalse(f.is_readonly)
        self.assertEqual(f.mime_type, "content/unknown")
        self.assertEqual(f.name, "package")
        self.assertEqual(f.parent.path, "data")
        self.assertEqual(f.path, "data/package")
        self.assertIn(os.path.abspath(os.path.curdir), f.url)
예제 #29
0
    def test_copy(self):
        """ folder copy """

        f = File("data/sub")
        self.assertFalse(f.exists)

        # Create the folder.
        f.create_folder()
        self.assertTrue(f.exists)
        self.assertRaises(ValueError, f.create_folder)

        self.assertEqual(len(f.children), 0)
        self.assertEqual(f.ext, "")
        self.assertFalse(f.is_file)
        self.assertTrue(f.is_folder)
        self.assertEqual(f.mime_type, "content/unknown")
        self.assertEqual(f.name, "sub")
        self.assertEqual(f.path, "data/sub")

        # Copy the folder.
        g = File("data/copy")
        self.assertFalse(g.exists)

        f.copy(g)
        self.assertTrue(g.exists)

        self.assertEqual(len(g.children), 0)
        self.assertEqual(g.ext, "")
        self.assertFalse(g.is_file)
        self.assertTrue(g.is_folder)
        self.assertEqual(g.mime_type, "content/unknown")
        self.assertEqual(g.name, "copy")
        self.assertEqual(g.path, "data/copy")

        # Attempt to copy a non-existent folder (should do nothing).
        f = File("data/bogus")
        self.assertFalse(f.exists)

        g = File("data/bogus_copy")
        self.assertFalse(g.exists)

        f.copy(g)
        self.assertFalse(g.exists)
    def test_copy(self):
        """ file copy """

        content = 'print "Hello World!"\n'

        f = File('data/foo.txt')
        self.assertEqual(f.exists, False)

        # Create the file.
        f.create_file(content)
        self.assertEqual(f.exists, True)
        self.assertRaises(ValueError, f.create_file, content)

        self.assertEqual(f.children, None)
        self.assertEqual(f.ext, '.txt')
        self.assertEqual(f.is_file, True)
        self.assertEqual(f.is_folder, False)
        self.assertEqual(f.mime_type, 'text/plain')
        self.assertEqual(f.name, 'foo')
        self.assertEqual(f.path, 'data/foo.txt')

        # Copy the file.
        g = File('data/bar.txt')
        self.assertEqual(g.exists, False)

        f.copy(g)
        self.assertEqual(g.exists, True)

        self.assertEqual(g.children, None)
        self.assertEqual(g.ext, '.txt')
        self.assertEqual(g.is_file, True)
        self.assertEqual(g.is_folder, False)
        self.assertEqual(g.mime_type, 'text/plain')
        self.assertEqual(g.name, 'bar')
        self.assertEqual(g.path, 'data/bar.txt')

        # Attempt to copy a non-existent file (should do nothing).
        f = File('data/bogus.xx')
        self.assertEqual(f.exists, False)

        g = File('data/bogus_copy.txt')
        self.assertEqual(g.exists, False)

        f.copy(g)
        self.assertEqual(g.exists, False)

        return
예제 #31
0
    def test_properties(self):
        """ folder properties """

        # Properties of a non-existent folder.
        f = File('data/bogus')

        self.assert_(os.path.abspath(os.path.curdir) in f.absolute_path)
        self.assertEqual(f.children, None)
        self.assertEqual(f.ext, '')
        self.assertEqual(f.exists, False)
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, False)
        self.assertEqual(f.is_package, False)
        self.assertEqual(f.is_readonly, False)
        self.assertEqual(f.mime_type, 'content/unknown')
        self.assertEqual(f.name, 'bogus')
        self.assertEqual(f.parent.path, 'data')
        self.assertEqual(f.path, 'data/bogus')
        self.assert_(os.path.abspath(os.path.curdir) in f.url)
        self.assertEqual(str(f), 'File(%s)' % f.path)

        # Properties of an existing folder.
        f = File('data/sub')
        f.create_folder()

        self.assert_(os.path.abspath(os.path.curdir) in f.absolute_path)
        self.assertEqual(len(f.children), 0)
        self.assertEqual(f.ext, '')
        self.assertEqual(f.exists, True)
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, True)
        self.assertEqual(f.is_package, False)
        self.assertEqual(f.is_readonly, False)
        self.assertEqual(f.mime_type, 'content/unknown')
        self.assertEqual(f.name, 'sub')
        self.assertEqual(f.parent.path, 'data')
        self.assertEqual(f.path, 'data/sub')
        self.assert_(os.path.abspath(os.path.curdir) in f.url)

        # Make it readonly.
        os.chmod(f.path, stat.S_IRUSR)
        self.assertEqual(f.is_readonly, True)

        # And then make it NOT readonly so that we can delete it at the end of
        # the test!
        os.chmod(f.path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
        self.assertEqual(f.is_readonly, False)

        # Properties of a Python package folder.
        f = File('data/package')
        f.create_folder()

        init = File('data/package/__init__.py')
        init.create_file()

        self.assert_(os.path.abspath(os.path.curdir) in f.absolute_path)
        self.assertEqual(len(f.children), 1)
        self.assertEqual(f.ext, '')
        self.assertEqual(f.exists, True)
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, True)
        self.assertEqual(f.is_package, True)
        self.assertEqual(f.is_readonly, False)
        self.assertEqual(f.mime_type, 'content/unknown')
        self.assertEqual(f.name, 'package')
        self.assertEqual(f.parent.path, 'data')
        self.assertEqual(f.path, 'data/package')
        self.assert_(os.path.abspath(os.path.curdir) in f.url)

        return
예제 #32
0
    def test_copy(self):
        """ file copy """

        content = 'print("Hello World!")\n'

        f = File("data/foo.txt")
        self.assertFalse(f.exists)

        # Create the file.
        f.create_file(content)
        self.assertTrue(f.exists)
        self.assertRaises(ValueError, f.create_file, content)

        self.assertIsNone(f.children)
        self.assertEqual(f.ext, ".txt")
        self.assertTrue(f.is_file)
        self.assertFalse(f.is_folder)
        self.assertEqual(f.mime_type, "text/plain")
        self.assertEqual(f.name, "foo")
        self.assertEqual(f.path, "data/foo.txt")

        # Copy the file.
        g = File("data/bar.txt")
        self.assertFalse(g.exists)

        f.copy(g)
        self.assertTrue(g.exists)

        self.assertIsNone(g.children)
        self.assertEqual(g.ext, ".txt")
        self.assertTrue(g.is_file)
        self.assertFalse(g.is_folder)
        self.assertEqual(g.mime_type, "text/plain")
        self.assertEqual(g.name, "bar")
        self.assertEqual(g.path, "data/bar.txt")

        # Attempt to copy a non-existent file (should do nothing).
        f = File("data/bogus.xx")
        self.assertFalse(f.exists)

        g = File("data/bogus_copy.txt")
        self.assertFalse(g.exists)

        f.copy(g)
        self.assertFalse(g.exists)
    def test_copy(self):
        """ folder copy """

        f = File('data/sub')
        self.assertEqual(f.exists, False)

        # Create the folder.
        f.create_folder()
        self.assertEqual(f.exists, True)
        self.assertRaises(ValueError, f.create_folder)

        self.assertEqual(len(f.children), 0)
        self.assertEqual(f.ext, '')
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, True)
        self.assertEqual(f.mime_type, 'content/unknown')
        self.assertEqual(f.name, 'sub')
        self.assertEqual(f.path, 'data/sub')

        # Copy the folder.
        g = File('data/copy')
        self.assertEqual(g.exists, False)

        f.copy(g)
        self.assertEqual(g.exists, True)

        self.assertEqual(len(g.children), 0)
        self.assertEqual(g.ext, '')
        self.assertEqual(g.is_file, False)
        self.assertEqual(g.is_folder, True)
        self.assertEqual(g.mime_type, 'content/unknown')
        self.assertEqual(g.name, 'copy')
        self.assertEqual(g.path, 'data/copy')

        # Attempt to copy a non-existent folder (should do nothing).
        f = File('data/bogus')
        self.assertEqual(f.exists, False)

        g = File('data/bogus_copy')
        self.assertEqual(g.exists, False)

        f.copy(g)
        self.assertEqual(g.exists, False)

        return
    def test_properties(self):
        """ folder properties """

        # Properties of a non-existent folder.
        f = File('data/bogus')

        self.assertTrue(os.path.abspath(os.path.curdir) in f.absolute_path)
        self.assertEqual(f.children, None)
        self.assertEqual(f.ext, '')
        self.assertEqual(f.exists, False)
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, False)
        self.assertEqual(f.is_package, False)
        self.assertEqual(f.is_readonly, False)
        self.assertEqual(f.mime_type, 'content/unknown')
        self.assertEqual(f.name, 'bogus')
        self.assertEqual(f.parent.path, 'data')
        self.assertEqual(f.path, 'data/bogus')
        self.assertTrue(os.path.abspath(os.path.curdir) in f.url)
        self.assertEqual(str(f), 'File(%s)' % f.path)

        # Properties of an existing folder.
        f = File('data/sub')
        f.create_folder()

        self.assertTrue(os.path.abspath(os.path.curdir) in f.absolute_path)
        self.assertEqual(len(f.children), 0)
        self.assertEqual(f.ext, '')
        self.assertEqual(f.exists, True)
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, True)
        self.assertEqual(f.is_package, False)
        self.assertEqual(f.is_readonly, False)
        self.assertEqual(f.mime_type, 'content/unknown')
        self.assertEqual(f.name, 'sub')
        self.assertEqual(f.parent.path, 'data')
        self.assertEqual(f.path, 'data/sub')
        self.assertTrue(os.path.abspath(os.path.curdir) in f.url)

        # Make it readonly.
        os.chmod(f.path, stat.S_IRUSR)
        self.assertEqual(f.is_readonly, True)

        # And then make it NOT readonly so that we can delete it at the end of
        # the test!
        os.chmod(f.path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
        self.assertEqual(f.is_readonly, False)

        # Properties of a Python package folder.
        f = File('data/package')
        f.create_folder()

        init = File('data/package/__init__.py')
        init.create_file()

        self.assertTrue(os.path.abspath(os.path.curdir) in f.absolute_path)
        self.assertEqual(len(f.children), 1)
        self.assertEqual(f.ext, '')
        self.assertEqual(f.exists, True)
        self.assertEqual(f.is_file, False)
        self.assertEqual(f.is_folder, True)
        self.assertEqual(f.is_package, True)
        self.assertEqual(f.is_readonly, False)
        self.assertEqual(f.mime_type, 'content/unknown')
        self.assertEqual(f.name, 'package')
        self.assertEqual(f.parent.path, 'data')
        self.assertEqual(f.path, 'data/package')
        self.assertTrue(os.path.abspath(os.path.curdir) in f.url)

        return