sys.stdout.getvalue.strip

Here are the examples of the python api sys.stdout.getvalue.strip taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

30 Examples 7

Example 1

Project: pygogo
Source File: test_main.py
View license
    def test_handlers(self):
        f = StringIO()
        hdlr = gogo.handlers.fileobj_hdlr(f)
        lggr = gogo.Gogo('test_handlers', high_hdlr=hdlr).logger

        msg1 = 'stdout hdlr only'
        lggr.debug(msg1)
        f.seek(0)
        nt.assert_equal(msg1, sys.stdout.getvalue().strip())
        nt.assert_false(f.read())

        msg2 = 'both hdlrs'
        lggr.error(msg2)
        f.seek(0)
        nt.assert_equal('%s\n%s' % (msg1, msg2), sys.stdout.getvalue().strip())
        nt.assert_equal(f.read().strip(), msg2)

Example 2

Project: ck
Source File: test_kernel.py
View license
    def test_inp(self):
        with test_util.tmp_sys('test input'):
            r = ck.inp({'text': 'test output'})
            self.assertEqual('test output', sys.stdout.getvalue().strip())
            self.assertEqual('test input', r['string'])
            self.assertEqual(0, r['return'])

Example 3

Project: ck
Source File: test_kernel.py
View license
    def test_select_uoa(self):
        lst = [
            {'data_uid': 'uid1', 'data_uoa': 'b'},
            {'data_uid': 'uid2', 'data_uoa': 'a'}
        ]
        with test_util.tmp_sys('1\n'):
            r = ck.select_uoa({'choices': lst})

            self.assertEqual('0) a (uid2)\n1) b (uid1)\n\nSelect UOA (or press Enter for 0):', sys.stdout.getvalue().strip())
            self.assertEqual(0, r['return'])
            self.assertEqual('uid1', r['choice'])

        with test_util.tmp_sys('2\n'):
            r = ck.select_uoa({'choices': lst})
            self.assertEqual(1, r['return'])
            self.assertEqual('number is not recognized', r['error'])

Example 4

Project: ck
Source File: test_kernel.py
View license
    def test_input_json(self):
        content = '{"a": 1, "b": [2, 3]}\n\n'
        with test_util.tmp_sys(content):
            r = ck.input_json({'text': 'input json'})
            self.assertEqual(0, r['return'])
            self.assertEqual('input json', sys.stdout.getvalue().strip())
            self.assertEqual(content.strip(), r['string'])
            self.assertEqual({'a': 1, 'b': [2, 3]}, r['dict'])

Example 5

Project: ck
Source File: test_mgmt.py
View license
    def test_perform_action_on_remote_repo(self):
        with test_util.tmp_repo(cfg={'remote': 'yes', 'url': 'http://cknowledge.org/repo/ck.php?'}) as repo:
            repo_uoa = repo['data_uid']
            with test_util.tmp_sys():
                r = ck.perform_action({
                    'repo_uoa': repo_uoa,
                    'data_uoa': 'default',
                    'module_uoa': 'repo',
                    'action': 'search',
                    'out': 'con'})
                self.assertEqual(0, r['return'])
                self.assertEqual('default:repo:default', sys.stdout.getvalue().strip())

        with test_util.tmp_repo(cfg={'remote': 'yes'}) as repo:
            repo_uoa = repo['data_uid']
            with test_util.tmp_sys():
                r = ck.perform_action({'repo_uoa': repo_uoa, 'action': 'search'})
                self.assertEqual(1, r['return'])
                self.assertEqual('URL of remote repository is not defined', r['error'])

Example 6

Project: fabric
Source File: test_context_managers.py
View license
    @server()
    @mock_streams('both')
    def test_warn_only_does_not_imply_hide_everything(self):
        with warn_only():
            run("ls /simple")
            assert sys.stdout.getvalue().strip() != ""

Example 7

Project: pythonect
Source File: test_interpreter.py
View license
    @unittest.skipIf(_not_buffered(), 'sys.stdout is not buffered')
    def test_command_mode(self):

        pythonect_interpreter.main(argv=shlex.split("""pythonect -c '"Hello, world" -> print'"""))

        self.assertRegexpMatches(sys.stdout.getvalue().strip(), '.*Hello, world.*')

Example 8

Project: pythonect
Source File: test_interpreter.py
View license
    @unittest.skipIf(_not_buffered(), 'sys.stdout is not buffered')
    def test_script_mode_p2y(self):

        pythonect_interpreter.main(argv=shlex.split('pythonect ' + TEST_DIR + os.sep + 'helloworld.p2y'))

        self.assertRegexpMatches(sys.stdout.getvalue().strip(), '.*Hello, world.*')

Example 9

Project: pythonect
Source File: test_interpreter.py
View license
    @unittest.skipIf(_not_buffered(), 'sys.stdout is not buffered')
    def test_script_mode_dia(self):

        pythonect_interpreter.main(argv=shlex.split('pythonect ' + TEST_DIR + os.sep + 'helloworld.dia'))

        self.assertRegexpMatches(sys.stdout.getvalue().strip(), '.*Hello, world.*')

Example 10

Project: pythonect
Source File: test_interpreter.py
View license
    @unittest.skipIf(_not_buffered(), 'sys.stdout is not buffered')
    def test_module_mode(self):

        pythonect_interpreter.main(argv=shlex.split('pythonect -m foobar'))

        self.assertRegexpMatches(sys.stdout.getvalue().strip(), '.*Hello, world.*')

Example 11

Project: pythonect
Source File: test_interpreter.py
View license
    @unittest.skipIf(_not_buffered(), 'sys.stdout is not buffered')
    def test_maxthreads_cmd_option(self):

        pythonect_interpreter.main(argv=shlex.split('pythonect -mt 1 -c "[1,2,3,4,5,6,7,8,9] -> print"'))

        self.assertTrue(len(set(re.findall('Thread-[\d]', sys.stdout.getvalue().strip()))) == 1)

Example 12

Project: dj-stripe
Source File: test_sync.py
View license
        def test_bad_sync(self):
            customer = sync_subscriber(self.user)
            customer.stripe_id = "fake_customer_id"
            customer.save()

            sync_subscriber(self.user)

            self.assertEqual("ERROR: No such customer: fake_customer_id", sys.stdout.getvalue().strip())

Example 13

Project: dj-stripe
Source File: test_sync.py
View license
        def test_bad_sync(self):
            customer = sync_subscriber(self.user)
            customer.stripe_id = "fake_customer_id"
            customer.save()

            sync_subscriber(self.user)

            self.assertEqual("ERROR: No such customer: fake_customer_id", sys.stdout.getvalue().strip())

Example 14

Project: dj-stripe
Source File: test_sync.py
View license
    @patch("djstripe.models.Customer.sync")
    @patch("djstripe.models.Customer.stripe_customer", new_callable=PropertyMock, return_value="test_stripe_customer")
    @patch("stripe.Customer.create", return_value=PropertyMock(id="cus_xxx1234567890"))
    def test_sync_fail(self, stripe_customer_create_mock, stripe_customer_mock, sync_mock):
        sync_mock.side_effect = stripe.InvalidRequestError("No such customer:", "blah")

        sync_subscriber(self.user)

        self.assertEqual("ERROR: No such customer:", sys.stdout.getvalue().strip())

Example 15

Project: dj-stripe
Source File: test_sync.py
View license
    @patch("stripe.Plan.create")
    def test_plan_exists(self, plan_create_mock):
        plan_create_mock.side_effect = stripe.StripeError("Plan already exists.")

        sync_plans(api_key)
        self.assertTrue("ERROR: Plan already exists.", sys.stdout.getvalue().strip())

Example 16

Project: dj-stripe
Source File: test_sync.py
View license
    @patch("djstripe.models.Customer.sync")
    @patch("djstripe.models.Customer.stripe_customer", new_callable=PropertyMock, return_value="test_stripe_customer")
    @patch("stripe.Customer.create", return_value=PropertyMock(id="cus_xxx1234567890"))
    def test_sync_fail(self, stripe_customer_create_mock, stripe_customer_mock, sync_mock):
        sync_mock.side_effect = stripe.InvalidRequestError("No such customer:", "blah")

        sync_subscriber(self.user)

        self.assertEqual("ERROR: No such customer:", sys.stdout.getvalue().strip())

Example 17

Project: dj-stripe
Source File: test_sync.py
View license
    @patch("stripe.Plan.create")
    def test_plan_exists(self, plan_create_mock):
        plan_create_mock.side_effect = stripe.StripeError("Plan already exists.")

        sync_plans(api_key)
        self.assertTrue("ERROR: Plan already exists.", sys.stdout.getvalue().strip())

Example 18

Project: neurokernel
Source File: test_mixins.py
View license
    def test_methods(self):
        self.lm.log_debug('abc')
        self.lm.log_info('abc')
        self.lm.log_warning('abc')
        self.lm.log_error('abc')
        self.lm.log_critical('abc')

        # All output to stdout is buffered within a single test before emission:
        self.assertEquals(sys.stdout.getvalue().strip(),
                          'log:DEBUG:abc\n'
                          'log:INFO:abc\n'
                          'log:WARNING:abc\n'
                          'log:ERROR:abc\n'
                          'log:CRITICAL:abc')

Example 19

Project: neurokernel
Source File: test_mixins.py
View license
    def test_log_on(self):
        self.lm.log_on = False
        self.lm.log_debug('abc')
        self.lm.log_info('abc')
        self.lm.log_warning('abc')
        self.lm.log_error('abc')
        self.lm.log_critical('abc')
        self.assertEquals(sys.stdout.getvalue().strip(), '')

Example 20

Project: pygogo
Source File: test_main.py
View license
    def test_multiple_loggers(self):
        f = StringIO()

        going = gogo.Gogo(
            'myapp',
            low_hdlr=gogo.handlers.fileobj_hdlr(f),
            low_formatter=gogo.formatters.fixed_formatter,
            high_hdlr=gogo.handlers.stdout_hdlr(),
            high_level='info',
            high_formatter=gogo.formatters.console_formatter)

        root = going.logger
        logger1 = going.get_logger('area1')
        logger2 = going.get_logger('area2')

        root.info('Jackdaws love my big sphinx of quartz.')
        logger1.debug('Quick zephyrs blow, vexing daft Jim.')
        logger1.info('How quickly daft jumping zebras vex.')
        logger2.warning('Jail zesty vixen who grabbed pay.')
        logger2.error('The five boxing wizards jump quickly.')

        console_msg = (
            "myapp.base  : INFO     Jackdaws love my big sphinx of quartz."
            "\nmyapp.area1 : INFO     How quickly daft jumping zebras vex."
            "\nmyapp.area2 : WARNING  Jail zesty vixen who grabbed pay."
            "\nmyapp.area2 : ERROR    The five boxing wizards jump quickly.")

        file_msg = [
            "myapp.base   INFO     Jackdaws love my big sphinx of quartz.\n",
            "myapp.area1  DEBUG    Quick zephyrs blow, vexing daft Jim.\n",
            "myapp.area1  INFO     How quickly daft jumping zebras vex.\n",
            "myapp.area2  WARNING  Jail zesty vixen who grabbed pay.\n",
            "myapp.area2  ERROR    The five boxing wizards jump quickly.\n"]

        f.seek(0)
        nt.assert_equal(console_msg, sys.stdout.getvalue().strip())
        nt.assert_equal([line[24:] for line in f], file_msg)

Example 21

Project: pygogo
Source File: test_main.py
View license
    def test_params_and_looping(self):
        levels = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL')
        f = StringIO()
        going = gogo.Gogo(low_hdlr=gogo.handlers.fileobj_hdlr(f))
        logger1 = going.get_logger('area1')
        logger2 = gogo.Gogo().get_logger('area2')

        logger1_msg = 'A debug message\nAn info message'
        logger1.debug('A debug message')
        logger1.info('An info %s', 'message')
        f.seek(0)
        nt.assert_equal(f.read().strip(), logger1_msg)
        logger2_msg = ''

        for level in [getattr(logging, l) for l in levels]:
            name = logging.getLevelName(level)
            logger2_msg += '%s message\n' % name
            logger2.log(level, '%s %s', name, 'message')
            # TODO: lookup yielding from a nose test

        nt.assert_equal(logger2_msg.strip(), sys.stdout.getvalue().strip())

Example 22

Project: pygogo
Source File: test_main.py
View license
    def test_debugging(self):
        console_msg = (
            'This should log\nSo should this\nAnd this too\nThis should log '
            'also\nSo should this\nAnd this too\nBut this one should\nAnd this'
            ' one too')

        logger = gogo.Gogo('debug.none').logger
        logger.debug('This should log')
        logger.info('So should this')
        logger.warning('And this too')

        logger = gogo.Gogo('debug.on', verbose=True).logger
        logger.debug('This should log also')
        logger.info('So should this')
        logger.warning('And this too')

        logger = gogo.Gogo('debug.off', verbose=False).logger
        logger.debug("This shouldn't log")
        logger.info('But this one should')
        logger.warning('And this one too')

        results = sys.stdout.getvalue().strip()
        nt.assert_in("This should log", results)
        nt.assert_not_in("This shouldn't log", results)
        nt.assert_equal(console_msg, results)

Example 23

Project: gitcheck
Source File: tests.py
View license
    def test_gitcheck(self):
        os.chdir(GITROOT)

        defaulttheme = ""
        gitcheck.colortheme = {
            'default': defaulttheme,
            'prjchanged': defaulttheme,
            'prjremote': defaulttheme,
            'prjname': defaulttheme,
            'reponame': defaulttheme,
            'branchname': defaulttheme,
            'fileupdated': defaulttheme,
            'remoteto': defaulttheme,
            'committo': defaulttheme,
            'commitinfo': defaulttheme,
            'commitstate': defaulttheme,
            'bell': defaulttheme,
            'reset': defaulttheme,
        }

        gitcheck.gitcheck()

        output = sys.stdout.getvalue().strip()
        lines = output.split('\n')

        self.assertEqual(lines[0], 'fabrecipes/master ')
        self.assertEqual(lines[1], 'gitcheck/master ')
        self.assertEqual(lines[2], 'serialkiller/master')

Example 24

Project: ck
Source File: test_kernel.py
View license
    def test_out(self):
        with test_util.tmp_sys():
            ck.out('test')
            self.assertEqual('test', sys.stdout.getvalue().strip())

Example 25

Project: ck
Source File: test_kernel.py
View license
    def test_err(self):
        with test_util.tmp_sys():
            ck.err({'return': 2, 'error': 'test.'})
            self.assertEqual('Error: test.\nExit code: 2', sys.stdout.getvalue().strip())

Example 26

Project: ck
Source File: test_kernel.py
View license
    def test_jerr(self):
        with test_util.tmp_sys():
            with self.assertRaises(KeyboardInterrupt):
                ck.jerr({'return': 2, 'error': 'test.'})
            self.assertEqual('Error: test.', sys.stdout.getvalue().strip())

Example 27

Project: ck
Source File: test_kernel.py
View license
    def test_select(self):
        d = {
            'key0': { 'name': 'n0', 'sort': 1 },
            'key1': { 'name': 'n1', 'sort': 0 }
        }
        with test_util.tmp_sys('1\n'):
            r = ck.select({'dict': d, 'title': 'Select:'})

            self.assertEqual('Select:\n\n0) n1\n1) n0\n\nMake your selection (or press Enter for 0):', sys.stdout.getvalue().strip())
            self.assertEqual(0, r['return'])
            self.assertEqual('key0', r['string'])

        with test_util.tmp_sys('\n'):
            r = ck.select({'dict': d, 'title': 'Select:', 'error_if_empty': 'yes'})
            self.assertEqual(1, r['return'])
            self.assertEqual('selection is empty', r['error'])

        with test_util.tmp_sys('\n'):
            r = ck.select({'dict': d, 'title': 'Select:'})
            self.assertEqual(0, r['return'])
            self.assertEqual('key1', r['string'])

        with test_util.tmp_sys('2\n'):
            r = ck.select({'dict': d, 'title': 'Select:'})
            self.assertEqual(1, r['return'])
            self.assertEqual('selection is not recognized', r['error'])

Example 28

Project: ck
Source File: test_mgmt.py
View license
    def test_perform_remote_action(self):
        r = ck.perform_remote_action({
            'module_uoa': 'kernel', 
            'remote_server_url': 'http://cknowledge.org/repo/ck.php?',
            'data_uoa': 'default',
            'repo_uoa': 'default',
            'action': 'search',
            'cid': 'invalid_cid_for_deletion'})
        self.assertEqual(0, r['return'])
        lst = r['lst']
        self.assertEqual(1, len(lst))
        r = lst[0]
        self.assertEqual('kernel', r['module_uoa'])
        self.assertEqual('default', r['data_uoa'])
        self.assertEqual('default', r['repo_uoa'])
        self.assertIn('repo_uid', r)
        self.assertIn('module_uid', r)
        self.assertIn('data_uid', r)
        self.assertIn('path', r)

        with test_util.tmp_sys():
            r = ck.perform_remote_action({
                'module_uoa': 'kernel',
                'remote_server_url': 'http://cknowledge.org/repo/ck.php?',
                'data_uoa': 'default',
                'repo_uoa': 'default',
                'action': 'search',
                'out': 'con'})
            self.assertEqual(0, r['return'])
            self.assertEqual('default:kernel:default', sys.stdout.getvalue().strip())

        r = ck.perform_remote_action({
            'module_uoa': 'kernel', 
            'remote_server_url': 'http://cknowledge.org/repo/ck.php?',
            'data_uoa': 'default',
            'repo_uoa': 'default',
            'action': 'push',
            'cids': ['']})
        self.assertEqual(1, r['return'])
        self.assertEqual('filename is empty', r['error'])

        missing_filename = ck.gen_uid({})['data_uid']
        r = ck.perform_remote_action({
            'module_uoa': 'kernel', 
            'remote_server_url': 'http://cknowledge.org/repo/ck.php?',
            'data_uoa': 'default',
            'repo_uoa': 'default',
            'action': 'push',
            'filename': missing_filename})
        self.assertEqual(1, r['return'])
        self.assertEqual('file '+missing_filename+' not found', r['error'])

        with test_util.tmp_file(content='abcd') as fname:
            missing_user = ck.gen_uid({})['data_uid']
            missing_pass = ck.gen_uid({})['data_uid']
            r = ck.perform_remote_action({
                'module_uoa': 'kernel', 
                'remote_server_url': 'http://cknowledge.org/repo/ck.php?',
                'data_uoa': 'default',
                'repo_uoa': 'default',
                'action': 'push',
                'filename': fname,
                'remote_server_user': missing_user,
                'remote_server_pass': missing_pass})
            self.assertEqual(1, r['return'])
            self.assertEqual('CK error: [kernel] writing to default repo is forbidden!', r['error'].strip())

        with test_util.tmp_dir(cwd=True):
            r = ck.perform_remote_action({
                'module_uoa': 'kernel', 
                'remote_server_url': 'http://cknowledge.org/repo/ck.php?',
                'data_uoa': 'default',
                'repo_uoa': 'default',
                'action': 'pull',
                'filename': '.cm/meta.json',
                'out': 'con'})
            self.assertEqual(0, r['return'])

Example 29

Project: dj-stripe
Source File: test_sync.py
View license
    @patch("stripe.Plan.create")
    def test_plan_created(self, plan_create_mock):
        sync_plans(api_key)
        self.assertTrue("Plan created for test", sys.stdout.getvalue().strip())

        plan_create_mock.assert_any_call(amount=1000,
                                        interval="month",
                                        name="Test Plan 0",
                                        currency="usd",
                                        id="test_id_0",
                                        interval_count=None,
                                        trial_period_days=None,
                                        statement_descriptor=None,
                                        metadata=None)

        plan_create_mock.assert_any_call(amount=2500,
                                        interval="month",
                                        name="Test Plan 1",
                                        currency="usd",
                                        id="test_id",
                                        interval_count=None,
                                        trial_period_days=None,
                                        statement_descriptor=None,
                                        metadata=None)

        plan_create_mock.assert_any_call(amount=5000,
                                        interval="month",
                                        name="Test Plan 2",
                                        currency="usd",
                                        id="test_id_2",
                                        interval_count=None,
                                        trial_period_days=None,
                                        statement_descriptor=None,
                                        metadata=None)

        plan_create_mock.assert_any_call(amount=5000,
                                        interval="month",
                                        name="Test Plan 3",
                                        currency="usd",
                                        id="test_id_3",
                                        interval_count=None,
                                        trial_period_days=None,
                                        statement_descriptor=None,
                                        metadata=None)

        plan_create_mock.assert_any_call(amount=7000,
                                        interval="month",
                                        name="Test Plan 4",
                                        currency="usd",
                                        id="test_id_4",
                                        interval_count=None,
                                        trial_period_days=7,
                                        statement_descriptor=None,
                                        metadata=None)

        self.assertEqual(5, plan_create_mock.call_count)

Example 30

Project: dj-stripe
Source File: test_sync.py
View license
    @patch("stripe.Plan.create")
    def test_plan_created(self, plan_create_mock):
        sync_plans(api_key)
        self.assertTrue("Plan created for test", sys.stdout.getvalue().strip())

        plan_create_mock.assert_any_call(amount=1000,
                                        interval="month",
                                        name="Test Plan 0",
                                        currency="usd",
                                        id="test_id_0",
                                        interval_count=None,
                                        trial_period_days=None,
                                        statement_descriptor=None,
                                        metadata=None)

        plan_create_mock.assert_any_call(amount=2500,
                                        interval="month",
                                        name="Test Plan 1",
                                        currency="usd",
                                        id="test_id",
                                        interval_count=None,
                                        trial_period_days=None,
                                        statement_descriptor=None,
                                        metadata=None)

        plan_create_mock.assert_any_call(amount=5000,
                                        interval="month",
                                        name="Test Plan 2",
                                        currency="usd",
                                        id="test_id_2",
                                        interval_count=None,
                                        trial_period_days=None,
                                        statement_descriptor=None,
                                        metadata=None)

        plan_create_mock.assert_any_call(amount=5000,
                                        interval="month",
                                        name="Test Plan 3",
                                        currency="usd",
                                        id="test_id_3",
                                        interval_count=None,
                                        trial_period_days=None,
                                        statement_descriptor=None,
                                        metadata=None)

        plan_create_mock.assert_any_call(amount=7000,
                                        interval="month",
                                        name="Test Plan 4",
                                        currency="usd",
                                        id="test_id_4",
                                        interval_count=None,
                                        trial_period_days=7,
                                        statement_descriptor=None,
                                        metadata=None)

        self.assertEqual(5, plan_create_mock.call_count)