Esempio n. 1
0
    def testConfigWritePath(self):
        app = xdg.APPLICATION

        # the file should be created
        path = os.path.join(self.xdg_config_home, app, 'write')

        f = xdg.config_write_path('write', 'wb')
        self.assertEquals(f.name, path)
        self.assertEquals(f.mode, 'wb')

        # the subdir should be created
        path = os.path.join(self.xdg_config_home, app, 'subdir', 'write')
        f = xdg.config_write_path('subdir/write')
        self.assertEquals(os.path.isdir(os.path.join(
                    self.xdg_config_home, app, 'subdir')), True)
        self.assertEquals(f.name, path)
        # default mode is 'w'
        self.assertEquals(f.mode, 'w')

        f.write('abc')
        f.close()
        f = xdg.config_write_path('subdir/write', 'a')
        f.write('def')
        f.close()

        self.assertEquals(file(path).read(), 'abcdef')
Esempio n. 2
0
    def testConfigWritePath(self):
        app = xdg.APPLICATION

        # the file should be created
        path = os.path.join(self.xdg_config_home, app, 'write')

        f = xdg.config_write_path('write', 'wb')
        self.assertEquals(f.name, path)
        self.assertEquals(f.mode, 'wb')

        # the subdir should be created
        path = os.path.join(self.xdg_config_home, app, 'subdir', 'write')
        f = xdg.config_write_path('subdir/write')
        self.assertEquals(
            os.path.isdir(os.path.join(self.xdg_config_home, app, 'subdir')),
            True)
        self.assertEquals(f.name, path)
        # default mode is 'w'
        self.assertEquals(f.mode, 'w')

        f.write('abc')
        f.close()
        f = xdg.config_write_path('subdir/write', 'a')
        f.write('def')
        f.close()

        self.assertEquals(file(path).read(), 'abcdef')
Esempio n. 3
0
    def testUnsetHomedir(self):
        app = xdg.APPLICATION

        del os.environ['XDG_CONFIG_HOME']

        # with unset $XDG_CONFIG_HOME, $HOME/.config should be used
        f = xdg.config_write_path('unset', 'w')
        self.assertEquals(f.name, os.path.join(self.home, '.config',
                                               app, 'unset'))
        os.environ['XDG_CONFIG_HOME'] = self.xdg_config_home
Esempio n. 4
0
    def testUnsetHomedir(self):
        app = xdg.APPLICATION

        del os.environ['XDG_CONFIG_HOME']

        # with unset $XDG_CONFIG_HOME, $HOME/.config should be used
        f = xdg.config_write_path('unset', 'w')
        self.assertEquals(f.name,
                          os.path.join(self.home, '.config', app, 'unset'))
        os.environ['XDG_CONFIG_HOME'] = self.xdg_config_home
    def setUp(self):
        # create a fake list of recent connection files
        self.old_registrydir = configure.registrydir
        self.new_registrydir = self.mktemp()
        os.mkdir(self.new_registrydir)
        configure.registrydir = self.new_registrydir

        rc1 = file(os.path.join(self.new_registrydir, 'fake.connection'), 'w')
        _create_connection(rc1, 1234, 'test.host.com', 'fake-manager',
                                  '1', 'testuser', 'testpasswd')
        rc1.close()
        rc2 = file(os.path.join(self.new_registrydir, 'fake2.connection'), 'w')
        _create_connection(rc2, 1235, 'test2.host.com', 'fake-manager',
                                  '0', 'test2user', 'test2passwd')
        rc2.close()

        # this should not be picked up as a recent connection file
        nrc = file(os.path.join(self.new_registrydir, 'fake3'), 'w')
        _create_connection(nrc, 1236, 'testx.host.com', 'fake-manager',
                                  '1', 'testxuser', 'testxpasswd')
        nrc.close()

        # create a fake default connections file
        self.old_xdg_config_home = os.environ.get('XDG_CONFIG_HOME')
        self.new_xdg_config_home = self.mktemp()
        os.mkdir(self.new_xdg_config_home)
        os.environ['XDG_CONFIG_HOME'] = self.new_xdg_config_home

        def1 = xdg.config_write_path('connections', 'w')
        def1.write('<connections>')
        _create_connection(def1, '2*', 'test3.host.com', 'fake-manager',
                                  '1', 'testdefuser', 'testdefpasswd')
        _create_connection(def1, '*', '*.host', 'fake-manager',
                                  '*', 'x', 'testxpasswd')
        def1.write('</connections>')
        def1.close()
Esempio n. 6
0
    def setUp(self):
        # create a fake list of recent connection files
        self.old_registrydir = configure.registrydir
        self.new_registrydir = self.mktemp()
        os.mkdir(self.new_registrydir)
        configure.registrydir = self.new_registrydir

        rc1 = file(os.path.join(self.new_registrydir, 'fake.connection'), 'w')
        _create_connection(rc1, 1234, 'test.host.com', 'fake-manager',
                                  '1', 'testuser', 'testpasswd')
        rc1.close()
        rc2 = file(os.path.join(self.new_registrydir, 'fake2.connection'), 'w')
        _create_connection(rc2, 1235, 'test2.host.com', 'fake-manager',
                                  '0', 'test2user', 'test2passwd')
        rc2.close()

        # this should not be picked up as a recent connection file
        nrc = file(os.path.join(self.new_registrydir, 'fake3'), 'w')
        _create_connection(nrc, 1236, 'testx.host.com', 'fake-manager',
                                  '1', 'testxuser', 'testxpasswd')
        nrc.close()

        # create a fake default connections file
        self.old_xdg_config_home = os.environ.get('XDG_CONFIG_HOME')
        self.new_xdg_config_home = self.mktemp()
        os.mkdir(self.new_xdg_config_home)
        os.environ['XDG_CONFIG_HOME'] = self.new_xdg_config_home

        def1 = xdg.config_write_path('connections', 'w')
        def1.write('<connections>')
        _create_connection(def1, '2*', 'test3.host.com', 'fake-manager',
                                  '1', 'testdefuser', 'testdefpasswd')
        _create_connection(def1, '*', '*.host', 'fake-manager',
                                  '*', 'x', 'testxpasswd')
        def1.write('</connections>')
        def1.close()