# Path: pythoscope/cmdline.py
# def init_project(path, skip_inspection=False):
#     pythoscope_path = get_pythoscope_path(path)
# 
#     try:
#         log.debug("Initializing .pythoscope directory: %s" % (os.path.abspath(pythoscope_path)))
#         os.makedirs(pythoscope_path)
#         os.makedirs(get_points_of_entry_path(path))
#         os.makedirs(get_code_trees_path(path))
#     except OSError, err:
#         fail("Couldn't initialize Pythoscope directory: %s." % err.strerror)
# 
#     project = Project.from_directory(path)
#     if not skip_inspection:
#         log.debug("Performing initial static inspection of the project source code.")
#         inspect_project_statically(project)
#     project.save()
# 
# Path: pythoscope/store.py
# def get_pickle_path(project_path):
#     return os.path.join(project_path, PICKLE_SUBPATH)
# 
# Path: test/helper.py
# UNPICKABLE_OBJECT = types.ClassType('class', (), {})
# DATA_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data'))
# def data(name):
# def read_data(name):
# def P(path):
# def noindent(string):
#     def __init__(self, project=None, name="poe", content=""):
#     def clear_previous_run(self):
#     def get_content(self):
#     def __init__(self, code_trees_path):
#     def remember_code_tree(self, code_tree, module_subpath):
#     def recall_code_tree(self, module_subpath):
#     def forget_code_tree(self, module_subpath):
# def EmptyProject():
# def ProjectInDirectory(project_path):
# def with_modules(project, paths, create_files=True):
# def with_module(project, path, objects=[]):
# def with_points_of_entry(project, paths):
# def with_point_of_entry(project, path, content):
# def ProjectWithModules(paths, project_type=EmptyProject):
# def TestableProject(path, more_modules=[]):
# def EmptyProjectExecution():
# def make_fresh_serialize():
# def get_test_module_contents(project):
# def generate_single_test_module(template='unittest', **module_kwds):
# def get_test_cases(project):
# def tmpdir():
# def mkdirs(path):
# def putfile(directory, filename, contents):
# def putdir(directory, dirname):
#     def setUp(self):
#     def tearDown(self):
#     def setUp(self):
#     def tearDown(self):
#     def setUp(self):
#     def tearDown(self):
#     def setUp(self):
#     def tearDown(self):
#     def _get_log_output(self):
#     def setUp(self):
#     def tearDown(self):
# class PointOfEntryMock(PointOfEntry):
# class MemoryCodeTreesManager(CodeTreesManager):
# class Test(object):
# class TempDirectory(Test):
# class CustomSeparator(Test):
# class CapturedLogger(Test):
# class CapturedDebugLogger(CapturedLogger):
# class IgnoredWarnings(Test):


import gc
import os.path
import sys
import timeit
from pythoscope.cmdline import init_project
from pythoscope.store import get_pickle_path
from test.helper import putfile, rmtree, tmpdir


def make_class(name, methods_count=20):
    code = ["class %s(object):\n" % name]
    for i in range(methods_count):
        code.append("    def method_%d(self):\n        pass\n" % i)
    return ''.join(code)

def make_function(name):
    return "def %s():\n    pass\n" % name

def make_module(classes_count=10, functions_count=10):
    code = []
    for i in range(classes_count):
        code.append(make_class("Class%d" % i))
    for i in range(functions_count):
        code.append(make_function("function_%d" % i))
    return ''.join(code)

# Run the setup once, stmt n times and report the minimum running time.
#
# Based on timeit module. I had to modify it, because:
#  - timer.timeit(n) returns time of running stmt n times (the sum, not the minimum),
#  - min(timer.repeat(n, 1)) runs the setup n times.
timer_template = """
def inner(_n, _timer):
    _results = []
    %(setup)s
    for _i in range(_n):
        _t0 = _timer()

# Path: pythoscope/cmdline.py
# def init_project(path, skip_inspection=False):
#     pythoscope_path = get_pythoscope_path(path)
# 
#     try:
#         log.debug("Initializing .pythoscope directory: %s" % (os.path.abspath(pythoscope_path)))
#         os.makedirs(pythoscope_path)
#         os.makedirs(get_points_of_entry_path(path))
#         os.makedirs(get_code_trees_path(path))
#     except OSError, err:
#         fail("Couldn't initialize Pythoscope directory: %s." % err.strerror)
# 
#     project = Project.from_directory(path)
#     if not skip_inspection:
#         log.debug("Performing initial static inspection of the project source code.")
#         inspect_project_statically(project)
#     project.save()
# 
# Path: pythoscope/store.py
# def get_pickle_path(project_path):
#     return os.path.join(project_path, PICKLE_SUBPATH)
# 
# Path: test/helper.py
# UNPICKABLE_OBJECT = types.ClassType('class', (), {})
# DATA_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data'))
# def data(name):
# def read_data(name):
# def P(path):
# def noindent(string):
#     def __init__(self, project=None, name="poe", content=""):
#     def clear_previous_run(self):
#     def get_content(self):
#     def __init__(self, code_trees_path):
#     def remember_code_tree(self, code_tree, module_subpath):
#     def recall_code_tree(self, module_subpath):
#     def forget_code_tree(self, module_subpath):
# def EmptyProject():
# def ProjectInDirectory(project_path):
# def with_modules(project, paths, create_files=True):
# def with_module(project, path, objects=[]):
# def with_points_of_entry(project, paths):
# def with_point_of_entry(project, path, content):
# def ProjectWithModules(paths, project_type=EmptyProject):
# def TestableProject(path, more_modules=[]):
# def EmptyProjectExecution():
# def make_fresh_serialize():
# def get_test_module_contents(project):
# def generate_single_test_module(template='unittest', **module_kwds):
# def get_test_cases(project):
# def tmpdir():
# def mkdirs(path):
# def putfile(directory, filename, contents):
# def putdir(directory, dirname):
#     def setUp(self):
#     def tearDown(self):
#     def setUp(self):
#     def tearDown(self):
#     def setUp(self):
#     def tearDown(self):
#     def setUp(self):
#     def tearDown(self):
#     def _get_log_output(self):
#     def setUp(self):
#     def tearDown(self):
# class PointOfEntryMock(PointOfEntry):
# class MemoryCodeTreesManager(CodeTreesManager):
# class Test(object):
# class TempDirectory(Test):
# class CustomSeparator(Test):
# class CapturedLogger(Test):
# class CapturedDebugLogger(CapturedLogger):
# class IgnoredWarnings(Test):


# Path: tools/speed_benchmark.py
import gc
import os.path
import sys
import timeit
from pythoscope.cmdline import init_project
from pythoscope.store import get_pickle_path
from test.helper import putfile, rmtree, tmpdir



def make_class(name, methods_count=20):
    code = ["class %s(object):\n" % name]
    for i in range(methods_count):
        code.append("    def method_%d(self):\n        pass\n" % i)
    return ''.join(code)

def make_function(name):
    return "def %s():\n    pass\n" % name

def make_module(classes_count=10, functions_count=10):
    code = []
    for i in range(classes_count):
        code.append(make_class("Class%d" % i))
    for i in range(functions_count):
        code.append(make_function("function_%d" % i))
    return ''.join(code)

# Run the setup once, stmt n times and report the minimum running time.
#
# Based on timeit module. I had to modify it, because:
#  - timer.timeit(n) returns time of running stmt n times (the sum, not the minimum),
#  - min(timer.repeat(n, 1)) runs the setup n times.
timer_template = """
def inner(_n, _timer):
    _results = []
    %(setup)s
    for _i in range(_n):
        _t0 = _timer()

        %(stmt)s