Exemple #1
0
 def test_get_user_PROVIDERPATH_entry__respects_XDG_DATA_HOME(
         self, mock_getenv, mock_expanduser):
     """
     verify that get_user_PROVIDERPATH_entry() honors XDG_DATA_HOME
     """
     def getenv(name, default=None):
         if name == 'XDG_DATA_HOME':
             return '/home/user/xdg-data'
         else:
             self.fail(("no other environment should be consulted"
                        " (asked for {!r})".format(name)))
     mock_getenv.side_effect = getenv
     measured = get_user_PROVIDERPATH_entry()
     expected = "/home/user/xdg-data/plainbox-providers-1"
     self.assertEqual(measured, expected)
Exemple #2
0
    def test_get_user_PROVIDERPATH_entry__respects_XDG_DATA_HOME(
            self, mock_getenv, mock_expanduser):
        """
        verify that get_user_PROVIDERPATH_entry() honors XDG_DATA_HOME
        """
        def getenv(name, default=None):
            if name == 'XDG_DATA_HOME':
                return '/home/user/xdg-data'
            else:
                self.fail(("no other environment should be consulted"
                           " (asked for {!r})".format(name)))

        mock_getenv.side_effect = getenv
        measured = get_user_PROVIDERPATH_entry()
        expected = "/home/user/xdg-data/plainbox-providers-1"
        self.assertEqual(measured, expected)
 def invoked(self, ns):
     pathname = os.path.join(
         get_user_PROVIDERPATH_entry(),
         "{}.provider".format(self.definition.name.replace(':', '.')))
     if ns.uninstall:
         if os.path.isfile(pathname):
             _logger.info(_("Removing provider file: %s"), pathname)
             os.unlink(pathname)
     else:
         if os.path.isfile(pathname) and not ns.force:
             print(_("Provider file already exists: {}").format(pathname))
             return 1
         else:
             _logger.info(_("Creating provider file: %s"), pathname)
             os.makedirs(os.path.dirname(pathname), exist_ok=True)
             with open(pathname, 'wt', encoding='UTF-8') as stream:
                 self.definition.write(stream)
 def invoked(self, ns):
     pathname = os.path.join(
         get_user_PROVIDERPATH_entry(), "{}.provider".format(
             self.definition.name.replace(':', '.')))
     if ns.uninstall:
         if os.path.isfile(pathname):
             _logger.info(_("Removing provider file: %s"), pathname)
             os.unlink(pathname)
     else:
         if os.path.isfile(pathname) and not ns.force:
             print(_("Provider file already exists: {}").format(pathname))
             return 1
         else:
             _logger.info(_("Creating provider file: %s"), pathname)
             os.makedirs(os.path.dirname(pathname), exist_ok=True)
             with open(pathname, 'wt', encoding='UTF-8') as stream:
                 self.definition.write(stream)
Exemple #5
0
    def test_get_user_PROVIDERPATH_entry__unset_XDG_DATA_HOME(
            self, mock_getenv, mock_expanduser):
        """
        verify that get_user_PROVIDERPATH_entry() still works with unset
        XDG_DATA_HOME
        """
        def getenv(name, default=None):
            if name == 'XDG_DATA_HOME':
                return default
            else:
                self.fail(("no other environment should be consulted"
                           " (asked for {!r})".format(name)))
        mock_getenv.side_effect = getenv

        def expanduser(path):
            return path.replace("~", "/home/user")
        mock_expanduser.side_effect = expanduser
        measured = get_user_PROVIDERPATH_entry()
        expected = "/home/user/.local/share/plainbox-providers-1"
        self.assertEqual(measured, expected)
Exemple #6
0
    def test_get_user_PROVIDERPATH_entry__unset_XDG_DATA_HOME(
            self, mock_getenv, mock_expanduser):
        """
        verify that get_user_PROVIDERPATH_entry() still works with unset
        XDG_DATA_HOME
        """
        def getenv(name, default=None):
            if name == 'XDG_DATA_HOME':
                return default
            else:
                self.fail(("no other environment should be consulted"
                           " (asked for {!r})".format(name)))

        mock_getenv.side_effect = getenv

        def expanduser(path):
            return path.replace("~", "/home/user")

        mock_expanduser.side_effect = expanduser
        measured = get_user_PROVIDERPATH_entry()
        expected = "/home/user/.local/share/plainbox-providers-1"
        self.assertEqual(measured, expected)