コード例 #1
0
ファイル: test_thread.py プロジェクト: sniegu/alot
 def test_assert_that_some_accounts_are_defined(self):
     with mock.patch('alot.commands.thread.settings.get_accounts',
                     mock.Mock(return_value=[])) as cm1:
         with self.assertRaises(AssertionError) as cm2:
             thread.determine_sender(None)
     expected = ('no accounts set!',)
     cm1.assert_called_once_with()
     self.assertTupleEqual(cm2.exception.args, expected)
コード例 #2
0
ファイル: thread_test.py プロジェクト: narriral/alot
 def test_assert_that_some_accounts_are_defined(self):
     with mock.patch('alot.commands.thread.settings.get_accounts',
                     mock.Mock(return_value=[])) as cm1:
         with self.assertRaises(AssertionError) as cm2:
             thread.determine_sender(None)
     expected = ('no accounts set!',)
     cm1.assert_called_once_with()
     self.assertTupleEqual(cm2.exception.args, expected)
コード例 #3
0
    def _test(self,
              accounts=(),
              expected=(),
              mail=None,
              header_priority=None,
              force_realname=False,
              force_address=False):
        """This method collects most of the steps that need to be done for most
        tests.  Especially a closure to mock settings.get and a mock for
        settings.get_accounts are set up."""
        mail = self.mail if mail is None else mail
        header_priority = self.header_priority if header_priority is None \
            else header_priority

        def settings_get(arg):
            """Mock function for setting.get()"""
            if arg == "reply_account_header_priority":
                return header_priority
            elif arg.endswith('_force_realname'):
                return force_realname
            elif arg.endswith('_force_address'):
                return force_address

        with mock.patch('alot.commands.thread.settings.get_accounts',
                        mock.Mock(return_value=accounts)):
            with mock.patch('alot.commands.thread.settings.get', settings_get):
                actual = thread.determine_sender(mail)
        self.assertTupleEqual(actual, expected)
コード例 #4
0
ファイル: thread_test.py プロジェクト: narriral/alot
    def _test(self, accounts=(), expected=(), mail=None, header_priority=None,
              force_realname=False, force_address=False):
        """This method collects most of the steps that need to be done for most
        tests.  Especially a closure to mock settings.get and a mock for
        settings.get_accounts are set up."""
        mail = self.mail if mail is None else mail
        header_priority = self.header_priority if header_priority is None \
            else header_priority

        def settings_get(arg):
            """Mock function for setting.get()"""
            if arg == "reply_account_header_priority":
                return header_priority
            elif arg.endswith('_force_realname'):
                return force_realname
            elif arg.endswith('_force_address'):
                return force_address

        with mock.patch('alot.commands.thread.settings.get_accounts',
                        mock.Mock(return_value=accounts)):
            with mock.patch('alot.commands.thread.settings.get', settings_get):
                actual = thread.determine_sender(mail)
        self.assertTupleEqual(actual, expected)