python类main()的实例源码

test_odin_init.py 文件源码 项目:Odin 作者: JamesBrofos 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_odin_init(self):
        # Create a test file.
        path = "./test_portfolio_id/"
        main = path + IOFiles.main_file.value
        handlers = path + IOFiles.handlers_file.value
        settings = path + IOFiles.settings_file.value
        strategy = path + IOFiles.strategy_file.value
        fund = path + IOFiles.fund_file.value
        odin_init(path)
        # Assert that all of the requisite files exist.
        self.assertTrue(os.path.isdir(path))
        self.assertTrue(os.path.isfile(main))
        self.assertTrue(os.path.isfile(handlers))
        self.assertTrue(os.path.isfile(settings))
        self.assertTrue(os.path.isfile(strategy))
        self.assertTrue(os.path.isfile(fund))
        shutil.rmtree(path)
cert_manager_test.py 文件源码 项目:TCP-IP 作者: JackZ0 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _set_up_config(self, domain, custom_archive):
        # TODO: maybe provide NamespaceConfig.make_dirs?
        # TODO: main() should create those dirs, c.f. #902
        os.makedirs(os.path.join(self.config.live_dir, domain))
        config_file = configobj.ConfigObj()

        if custom_archive is not None:
            os.makedirs(custom_archive)
            config_file["archive_dir"] = custom_archive
        else:
            os.makedirs(os.path.join(self.config.default_archive_dir, domain))

        for kind in ALL_FOUR:
            config_file[kind] = os.path.join(self.config.live_dir, domain,
                                        kind + ".pem")

        config_file.filename = os.path.join(self.config.renewal_configs_dir,
                                       domain + ".conf")
        config_file.write()
        return config_file
main_test.py 文件源码 项目:TCP-IP 作者: JackZ0 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def setUp(self):
        self.domain = 'example.org'
        self.patches = [
            mock.patch('certbot.main._get_and_save_cert'),
            mock.patch('certbot.main.display_ops.success_installation'),
            mock.patch('certbot.main.display_ops.success_renewal'),
            mock.patch('certbot.main._init_le_client'),
            mock.patch('certbot.main._suggest_donation_if_appropriate'),
            mock.patch('certbot.main._report_new_cert'),
            mock.patch('certbot.main._find_cert')]

        self.mock_auth = self.patches[0].start()
        self.mock_success_installation = self.patches[1].start()
        self.mock_success_renewal = self.patches[2].start()
        self.mock_init = self.patches[3].start()
        self.mock_suggest_donation = self.patches[4].start()
        self.mock_report_cert = self.patches[5].start()
        self.mock_find_cert = self.patches[6].start()
main_test.py 文件源码 项目:TCP-IP 作者: JackZ0 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_certonly_abspath(self):
        cert = 'cert'
        key = 'key'
        chain = 'chain'
        fullchain = 'fullchain'

        with mock.patch('certbot.main.certonly') as mock_certonly:
            self._call(['certonly', '--cert-path', cert, '--key-path', 'key',
                        '--chain-path', 'chain',
                        '--fullchain-path', 'fullchain'])

        config, unused_plugins = mock_certonly.call_args[0]
        self.assertEqual(config.cert_path, os.path.abspath(cert))
        self.assertEqual(config.key_path, os.path.abspath(key))
        self.assertEqual(config.chain_path, os.path.abspath(chain))
        self.assertEqual(config.fullchain_path, os.path.abspath(fullchain))
main_test.py 文件源码 项目:TCP-IP 作者: JackZ0 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _test_renew_common(self, renewalparams=None, names=None,
                           assert_oc_called=None, **kwargs):
        self._make_dummy_renewal_config()
        with mock.patch('certbot.storage.RenewableCert') as mock_rc:
            mock_lineage = mock.MagicMock()
            mock_lineage.fullchain = "somepath/fullchain.pem"
            if renewalparams is not None:
                mock_lineage.configuration = {'renewalparams': renewalparams}
            if names is not None:
                mock_lineage.names.return_value = names
            mock_rc.return_value = mock_lineage
            with mock.patch('certbot.main.renew_cert') as mock_renew_cert:
                kwargs.setdefault('args', ['renew'])
                self._test_renewal_common(True, None, should_renew=False, **kwargs)

            if assert_oc_called is not None:
                if assert_oc_called:
                    self.assertTrue(mock_renew_cert.called)
                else:
                    self.assertFalse(mock_renew_cert.called)
main_test.py 文件源码 项目:TCP-IP 作者: JackZ0 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_unregister(self):
        mocked_storage = mock.MagicMock()
        mocked_storage.find_all.return_value = ["an account"]

        self.mocks['account'].AccountFileStorage.return_value = mocked_storage
        self.mocks['_determine_account'].return_value = (mock.MagicMock(), "foo")

        cb_client = mock.MagicMock()
        self.mocks['client'].Client.return_value = cb_client

        config = mock.MagicMock()
        unused_plugins = mock.MagicMock()

        res = main.unregister(config, unused_plugins)

        self.assertTrue(res is None)
        self.assertTrue(cb_client.acme.deactivate_registration.called)
        m = "Account deactivated."
        self.assertTrue(m in self.mocks['get_utility']().add_message.call_args[0][0])
tls_sni_01_test.py 文件源码 项目:TCP-IP 作者: JackZ0 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_perform1(self, mock_save):
        self.sni.add_chall(self.achalls[0])
        response = self.achalls[0].response(self.account_key)
        mock_setup_cert = mock.MagicMock(return_value=response)

        # pylint: disable=protected-access
        self.sni._setup_challenge_cert = mock_setup_cert

        responses = self.sni.perform()

        mock_setup_cert.assert_called_once_with(self.achalls[0])
        self.assertEqual([response], responses)
        self.assertEqual(mock_save.call_count, 1)

        # Make sure challenge config is included in main config
        http = self.sni.configurator.parser.parsed[
            self.sni.configurator.parser.config_root][-1]
        self.assertTrue(
            util.contains_at_depth(http, ['include', self.sni.challenge_conf], 1))
configurator_test.py 文件源码 项目:TCP-IP 作者: JackZ0 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_is_site_enabled(self):
        """Test if site is enabled.

        .. note:: This test currently fails for hard links
            (which may happen if you move dirs incorrectly)
        .. warning:: This test does not work when running using the
            unittest.main() function. It incorrectly copies symlinks.

        """
        self.assertTrue(self.config.is_site_enabled(self.vh_truth[0].filep))
        self.assertFalse(self.config.is_site_enabled(self.vh_truth[1].filep))
        self.assertTrue(self.config.is_site_enabled(self.vh_truth[2].filep))
        self.assertTrue(self.config.is_site_enabled(self.vh_truth[3].filep))
        with mock.patch("os.path.isdir") as mock_isdir:
            mock_isdir.return_value = False
            self.assertRaises(errors.ConfigurationError,
                              self.config.is_site_enabled,
                              "irrelevant")
test_terraindisplay.py 文件源码 项目:RandTerrainPy 作者: jackromo 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def setUp(self):
        self.ter1 = Terrain(100, 100)   # all black
        self.ter2 = Terrain(200, 200)   # all white
        for x in range(self.ter2.width):
            for y in range(self.ter2.length):
                self.ter2[x, y] = 1
        self.ter3 = Terrain(100, 100)   # main diagonal is increasing brightness downwards
        for x in range(self.ter3.width):
            for y in range(self.ter3.length):
                if x == y:
                    self.ter3[x, y] = float(y) / self.ter3.length
        self.ter4 = Terrain(200, 100)   # checkerboard pattern
        for x in range(self.ter4.width):
            for y in range(self.ter4.length):
                self.ter4[x, y] = 1 if (x + y) % 2 == 0 else 0
py31compat.py 文件源码 项目:python- 作者: secondtonone1 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def unittest_main(*args, **kwargs):
        if 'testRunner' in kwargs and kwargs['testRunner'] is None:
            kwargs['testRunner'] = unittest.TextTestRunner
        return unittest.main(*args, **kwargs)
test_ui_base.py 文件源码 项目:PyWallet 作者: AndreMiras 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def helper_setup(self, app):
        main.SCREEN_SWITCH_DELAY = 0.001
test_ui_base.py 文件源码 项目:PyWallet 作者: AndreMiras 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def helper_load_switch_account(self, app):
        """
        Helper method for loading the switch account screen and returning
        the class handling this view.
        """
        controller = app.controller
        # TODO: use dispatch('on_release') on navigation drawer
        controller.load_switch_account()
        self.advance_frames(1)
        switch_account = controller.switch_account
        self.assertEqual(switch_account.__class__, main.SwitchAccount)
        return switch_account
test_ui_base.py 文件源码 项目:PyWallet 作者: AndreMiras 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def helper_test_delete_last_account(self, app):
        """
        Trying to delete the last account, should not crash the app,
        refs #120.
        """
        controller = app.controller
        pywalib = controller.pywalib
        manage_existing = controller.manage_existing
        # makes sure there's only one account left
        self.assertEqual(
            len(pywalib.get_account_list()), 1)
        # deletes it
        delete_button_id = manage_existing.ids.delete_button_id
        delete_button_id.dispatch('on_release')
        # a confirmation popup should show
        dialogs = controller.dialogs
        self.assertEqual(len(dialogs), 1)
        dialog = dialogs[0]
        self.assertEqual(dialog.title, 'Are you sure?')
        # confirm it
        manage_existing.on_delete_account_yes(dialog)
        # account was deleted dialog message
        dialogs = controller.dialogs
        self.assertEqual(len(dialogs), 1)
        dialog = dialogs[0]
        self.assertEqual(dialog.title, 'Account deleted, redirecting...')
        controller.dismiss_all_dialogs()
        self.advance_frames(1)
        # verifies the account was deleted
        self.assertEqual(len(pywalib.get_account_list()), 0)
        # this should be done by the events, but doesn't seem to happen
        # so we have to trigger it manually
        controller.history.current_account = None
        self.advance_frames(1)

    # main test function
py31compat.py 文件源码 项目:my-first-blog 作者: AnkurBegining 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def unittest_main(*args, **kwargs):
        if 'testRunner' in kwargs and kwargs['testRunner'] is None:
            kwargs['testRunner'] = unittest.TextTestRunner
        return unittest.main(*args, **kwargs)
test_main.py 文件源码 项目:PlasoScaffolder 作者: ClaudiaSaxer 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def testMainHelp(self):
    """testing the help of the main"""
    runner = CliRunner()
    result = runner.invoke(main.entry_point, ['--help'])
    expected_output = ('Usage: entry_point [OPTIONS] COMMAND [ARGS]...\n'
                       '\n'
                       'Options:\n'
                       '  --help  Show this message and exit.\n'
                       '\n'
                       'Commands:''\n'
                       '  sqlite\n')

    self.assertEqual(expected_output, str(result.output))
    self.assertEqual(0, result.exit_code)
test_main.py 文件源码 项目:PlasoScaffolder 作者: ClaudiaSaxer 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def testSQLiteRun(self, sqlite): #pylint: disable=unused-argument
    """testing the interaction with main and sqlite"""
    runner = CliRunner()
    result = runner.invoke(main.entry_point, ['sqlite'])
    self.assertEqual(0, result.exit_code)
    self.assertIsNone(result.exception)
    self.assertIsNone(result.exc_info)
test_examples.py 文件源码 项目:whatstyle 作者: mikr 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def main():
    unittest.main()
test_cli.py 文件源码 项目:run_lambda 作者: ethantkoenig 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def call(arguments):
        output = six.StringIO()
        with mock.patch("sys.stdout", output):
            with mock.patch("sys.argv", arguments):
                main.main()
        return str(output.getvalue())
main_test.py 文件源码 项目:benchmarks 作者: tensorflow 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def testArgumentInvalidFormat(self):
    self.assertEqual('', main.argument_name(''))
    self.assertEqual('', main.argument_name('arg=val'))
    self.assertEqual('', main.argument_name('-arg=val'))
    self.assertEqual('', main.argument_name('--argval'))
    self.assertEqual('', main.argument_name('--=val'))
    self.assertEqual('', main.argument_name('--='))
main_test.py 文件源码 项目:benchmarks 作者: tensorflow 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def testArgumentValidFormat(self):
    self.assertEqual('abc', main.argument_name('--abc=123'))
    self.assertEqual('a', main.argument_name('--a=123'))


问题


面经


文章

微信
公众号

扫码关注公众号