Пример #1
0
    def test_compile_path(self):
        self.assertTrue(compileall.compile_path(quiet=2))

        with test.test_importlib.util.import_state(path=[self.directory]):
            self.add_bad_source_file()
            self.assertFalse(compileall.compile_path(skip_curdir=False,
                                                     force=True, quiet=2))
Пример #2
0
    def run_tests_and_repeat(self, views, repeats=3):
        """
        Run the CATMAID performance tests and return a list of results and a
        list of repeats for every run.
        """
        from django.test.utils import setup_test_environment, \
            teardown_test_environment
        setup_test_environment()

        # Make sure all python code is compiled to not include this timing
        compileall.compile_path(maxlevels=10)
        self.log("Made sure all Python modules in sys.path are compiled")

        # We need a cursor to talk to the database
        cursor = self.connection.cursor()

        # Create test database, based on an existing template database
        db_name = "test_%s" % self.template_db_name

        self.create_db(cursor, db_name, self.template_db_name,
                       self.target_tablespace)

        # Store new database configuration
        self.connection.close()
        old_db_name = settings.DATABASES[self.connection.alias]["NAME"]
        settings.DATABASES[self.connection.alias]["NAME"] = db_name
        self.connection.settings_dict["NAME"] = db_name

        # Ensure a connection for the side effect of initializing the test
        # database and login.
        self.connection.ensure_connection()
        self.client.login(username=self.username, password=self.password)

        # Test all views
        self.log("Testing all %s views" % len(views))
        results = []
        repeat_results = []
        for v in views:
            # Ideally the DB cluster would be stopped here, OS caches would be
            # dropped (http://linux-mm.org/Drop_Caches) and then the DB cluster
            # would be restarted.
            results.append(self.test(v))
            for r in range(repeats):
                repeat_results.append(self.test(v))

        teardown_test_environment()

        # Restore the original database name
        self.connection.close()
        settings.DATABASES[self.connection.alias]["NAME"] = old_db_name
        self.connection.settings_dict["NAME"] = old_db_name
        self.connection.ensure_connection()
        self.drop_db(self.connection.cursor(), db_name)

        return results, repeat_results
Пример #3
0
    def run_tests_and_repeat(self, views, repeats=3):
        """
        Run the CATMAID performance tests and return a list of results and a
        list of repeats for every run.
        """
        from django.test.utils import setup_test_environment, \
            teardown_test_environment
        setup_test_environment()

        # Make sure all python code is compiled to not include this timing
        compileall.compile_path(maxlevels=10)
        self.log("Made sure all Python modules in sys.path are compiled")

        # We need a cursor to talk to the database
        cursor = self.connection.cursor()

        # Create test database, based on an existing template database
        db_name = "test_%s" % self.template_db_name

        self.create_db(cursor, db_name, self.template_db_name, self.target_tablespace)

        # Store new database configuration
        self.connection.close()
        old_db_name = settings.DATABASES[self.connection.alias]["NAME"]
        settings.DATABASES[self.connection.alias]["NAME"] = db_name
        self.connection.settings_dict["NAME"] = db_name

        # Ensure a connection for the side effect of initializing the test
        # database and login.
        self.connection.ensure_connection()
        self.client.login(username=self.username, password=self.password)

        # Test all views
        self.log("Testing all %s views" % len(views))
        results = []
        repeat_results = [[] for i in range(repeats)]
        for v in views:
            # Ideally the DB cluster would be stopped here, OS caches would be
            # dropped (http://linux-mm.org/Drop_Caches) and then the DB cluster
            # would be restarted.
            results.append(self.test(v))
            for r in range(repeats):
                repeat_results[r].append(self.test(v))

        teardown_test_environment()

        # Restore the original database name
        self.connection.close()
        settings.DATABASES[self.connection.alias]["NAME"] = old_db_name
        self.connection.settings_dict["NAME"] = old_db_name
        self.connection.ensure_connection()
        self.drop_db(self.connection.cursor(), db_name)

        return results, repeat_results
Пример #4
0
 def update_event(self, inp=-1):
     self.set_output_val(
         0,
         compileall.compile_path(self.input(0), self.input(1),
                                 self.input(2), self.input(3),
                                 self.input(4), self.input(5),
                                 self.input(6)))
Пример #5
0
    def test_compile_path(self):
        # Exclude Lib/test/ which contains invalid Python files like
        # Lib/test/badsyntax_pep3120.py
        testdir = os.path.realpath(os.path.dirname(__file__))
        if testdir in sys.path:
            self.addCleanup(setattr, sys, "path", sys.path)

            sys.path = list(sys.path)
            try:
                sys.path.remove(testdir)
            except ValueError:
                pass

        self.assertTrue(compileall.compile_path(quiet=2))

        with test.test_importlib.util.import_state(path=[self.directory]):
            self.add_bad_source_file()
            self.assertFalse(compileall.compile_path(skip_curdir=False, force=True, quiet=2))
Пример #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import compileall
import sys

sys.path[:] = ['examples', 'notthere']
print 'sys.path =', sys.path
compileall.compile_path()
Пример #7
0
                        print "ERROR: %s" % str(ex)
                    print >> sys.stderr, "ERROR compiling '%s': %s" % (
                        fullpath, str(ex))
                    errors.append((fullpath, ex))
        for d in excludes:
            if d in dirs:
                dirs.remove(d)
    return errors


if __name__ == "__main__":
    if '-c' in sys.argv:
        print "Removing all .pyc files..."
        for dir in base_dirs:
            clean_pyc_files(dir)
    else:
        errors = []
        for dir in base_dirs:
            errors.append(compile_python(dir))
        print
        if len(errors):
            print >> sys.stderr, "%d error(s) found!" % len(errors)
        else:
            print "CloudMailing's files successfully compiled!"

        import compileall

        print "Compiling Python Libraries..."
        compileall.compile_path(True, 10)
        print "Finished!"
Пример #8
0
                        help="removing all .pyc files")
    parser.add_argument('-a', action='store_true', dest='all',
                        help='compile also all installed python packages. ')
    parser.add_argument('folders', metavar='dir', nargs='*',
                        help='application folder to compile')

    args = parser.parse_args()

    base_dirs = args.folders
    if args.clear:
        print("Removing all .pyc files...")
        for dir_name in base_dirs:
            clean_pyc_files(dir_name)
    else:
        errors = []
        for dir_name in base_dirs:
            errors.append(compile_python(dir_name))
        print()
        if len(errors):
            sys.stderr.write("%d error(s) found!\n" % len(errors))
        else:
            print("Application's files successfully compiled!")

        if args.all:
            import compileall

            print("Compiling Python Libraries...")
            compileall.compile_path(True, 10)

        print("Finished!")