Beispiel #1
0
    server = None
    if TestBase.REQUIRES_INTEGRATION_SERVER in all_tags:
        ensure_port_available(8081)
        ensure_port_available(8000)
        server = start_integration_server(
            parsed_args.integration_server_start_cmd,
            all_tags.get(TestBase.REQUIRES_TESTING_MODULES, set()))

    result = unittest.TextTestRunner(verbosity=2).run(test_suite)

    if server:
        stop_integration_server(
            server, all_tags.get(TestBase.REQUIRES_TESTING_MODULES, set()))

    if result.errors or result.failures:
        raise Exception(
            'Test suite failed: %s errors, %s failures of '
            ' %s tests run.' %
            (len(result.errors), len(result.failures), result.testsRun))

    import tests.functional.actions as actions

    count = len(actions.UNIQUE_URLS_FOUND.keys())
    result.stream.writeln('INFO: Unique URLs found: %s' % count)
    result.stream.writeln('INFO: All %s tests PASSED!' % result.testsRun)


if __name__ == '__main__':
    appengine_config.gcb_force_default_encoding('ascii')
    main()
    # dev_appserver.fix_sys_path() prepends GAE paths to sys.path and hides
    # our classes like 'tests' behind other modules that have 'tests'.
    # Here, unlike dev_appserver, we append the path instead of prepending it,
    # so that our classes come first.
    sys.path += dev_appserver.EXTRA_PATHS[:]


def main():
    """Starts in-process server and runs all test cases in this module."""
    fix_sys_path()
    parsed_args = _PARSER.parse_args()

    result = unittest.TextTestRunner(verbosity=2).run(create_test_suite(parsed_args))

    if result.errors or result.failures:
        raise Exception(
            "Test suite failed: %s errors, %s failures of "
            " %s tests run." % (len(result.errors), len(result.failures), result.testsRun)
        )

    import tests.functional.actions as actions  # pylint: disable-msg=g-import-not-at-top

    count = len(actions.UNIQUE_URLS_FOUND.keys())
    result.stream.writeln("INFO: Unique URLs found: %s" % count)
    result.stream.writeln("INFO: All %s tests PASSED!" % result.testsRun)


if __name__ == "__main__":
    appengine_config.gcb_force_default_encoding("ascii")
    main()
    def test_string_encoding(self):
        """Test our understanding of Python string encoding aspects.

        We were quite naive to believe Python solves all string encoding issues
        automatically. That is not completely true and we have to do a lot of
        manual work to get it right. Here we capture some of the patterns.
        """
        original_encoding = sys.getdefaultencoding()

        # Test with 'ascii' default encoding. Note that GAE runs in 'ascii',
        # and not in 'utf-8'. There is no way to override this currently.
        appengine_config.gcb_force_default_encoding('ascii')

        # Note that Python bravely ignores the file encoding declaration
        # 'coding: utf-8' at the top of this file. The intuitive behavior would
        # be to change the default encoding to 'utf-8' for all the code running
        # in the scope of this file.

        # Initialization.
        test_1 = 'My Test Title Мой заголовок теста'
        test_2 = u'My Test Title Мой заголовок теста'

        # Types.
        assert isinstance(test_1, str)
        assert isinstance(test_2, unicode)
        assert test_1 != test_2

        # Conversions.
        assert_fails(lambda: unicode(test_1))
        assert unicode(test_1, 'utf-8')
        assert isinstance(unicode(test_1, 'utf-8'), unicode)
        assert unicode(test_1, 'utf-8') == test_2

        # Expressions.
        assert_fails(lambda: test_1 + test_2)
        assert_fails(lambda: '%s %s' % (test_1, test_2))
        assert_fails(lambda: u'%s %s' % (test_1, test_2))  # Why does it fail?
        assert_fails(lambda: ''.join([test_1, test_2]))
        assert_fails(lambda: u''.join([test_1, test_2]))  # Why does it fail?
        ''.join([unicode(test_1, 'utf-8'), test_2])

        # Test with 'utf-8' default encoding.
        appengine_config.gcb_force_default_encoding('utf-8')

        # Initialization.
        test_1 = 'My Test Title Мой заголовок теста'
        test_2 = u'My Test Title Мой заголовок теста'

        # Types.
        assert isinstance(test_1, str)  # How can this be true?
        assert isinstance(test_2, unicode)
        assert test_1 == test_2  # Note '!=' above, and '==' here. Who knew!!!

        # Conversions.
        assert unicode(test_1) == test_2
        assert unicode(test_1, 'utf-8') == test_2

        # Expressions.
        assert test_1 + test_2
        assert '%s %s' % (test_1, test_2)
        assert u'%s %s' % (test_1, test_2)

        # Clean up.
        appengine_config.gcb_force_default_encoding(original_encoding)
Beispiel #4
0
    def test_string_encoding(self):
        """Test our understanding of Python string encoding aspects.

        We were quite naive to believe Python solves all string encoding issues
        automatically. That is not completely true and we have to do a lot of
        manual work to get it right. Here we capture some of the patterns.
        """
        original_encoding = sys.getdefaultencoding()

        # Test with 'ascii' default encoding. Note that GAE runs in 'ascii',
        # and not in 'utf-8'. There is no way to override this currently.
        appengine_config.gcb_force_default_encoding('ascii')

        # Note that Python bravely ignores the file encoding declaration
        # 'coding: utf-8' at the top of this file. The intuitive behavior would
        # be to change the default encoding to 'utf-8' for all the code running
        # in the scope of this file.

        # Initialization.
        test_1 = 'My Test Title Мой заголовок теста'
        test_2 = u'My Test Title Мой заголовок теста'

        # Types.
        assert isinstance(test_1, str)
        assert isinstance(test_2, unicode)
        assert test_1 != test_2

        # Conversions.
        assert_fails(lambda: unicode(test_1))
        assert unicode(test_1, 'utf-8')
        assert isinstance(unicode(test_1, 'utf-8'), unicode)
        assert unicode(test_1, 'utf-8') == test_2

        # Expressions.
        assert_fails(lambda: test_1 + test_2)
        assert_fails(lambda: '%s %s' % (test_1, test_2))
        assert_fails(lambda: u'%s %s' % (test_1, test_2))  # Why does it fail?
        assert_fails(lambda: ''.join([test_1, test_2]))
        assert_fails(lambda: u''.join([test_1, test_2]))  # Why does it fail?
        ''.join([unicode(test_1, 'utf-8'), test_2])

        # Test with 'utf-8' default encoding.
        appengine_config.gcb_force_default_encoding('utf-8')

        # Initialization.
        test_1 = 'My Test Title Мой заголовок теста'
        test_2 = u'My Test Title Мой заголовок теста'

        # Types.
        assert isinstance(test_1, str)  # How can this be true?
        assert isinstance(test_2, unicode)
        assert test_1 == test_2  # Note '!=' above, and '==' here. Who knew!!!

        # Conversions.
        assert unicode(test_1) == test_2
        assert unicode(test_1, 'utf-8') == test_2

        # Expressions.
        assert test_1 + test_2
        assert '%s %s' % (test_1, test_2)
        assert u'%s %s' % (test_1, test_2)

        # Clean up.
        appengine_config.gcb_force_default_encoding(original_encoding)
Beispiel #5
0
    server = None
    if TestBase.REQUIRES_INTEGRATION_SERVER in all_tags:
        ensure_port_available(8081)
        ensure_port_available(8000)
        server = start_integration_server(
            parsed_args.integration_server_start_cmd,
            all_tags.get(TestBase.REQUIRES_TESTING_MODULES, set()))

    result = unittest.TextTestRunner(verbosity=2).run(test_suite)

    if server:
        stop_integration_server(
            server, all_tags.get(TestBase.REQUIRES_TESTING_MODULES, set()))

    if result.errors or result.failures:
        raise Exception(
            'Test suite failed: %s errors, %s failures of '
            ' %s tests run.' % (
                len(result.errors), len(result.failures), result.testsRun))

    import tests.functional.actions as actions

    count = len(actions.UNIQUE_URLS_FOUND.keys())
    result.stream.writeln('INFO: Unique URLs found: %s' % count)
    result.stream.writeln('INFO: All %s tests PASSED!' % result.testsRun)


if __name__ == '__main__':
    appengine_config.gcb_force_default_encoding('ascii')
    main()