コード例 #1
0
    def write(self, new_content):
        """Overwrite the file with new contents and update its created time.

        Creates the containing directories if needed.
        """
        ensure_directory(os.path.dirname(self.get_path()))
        write_content_to_file(new_content, self.get_path())
        self.created = time.time()
コード例 #2
0
ファイル: localizable.py プロジェクト: Br3nda/pythoscope
    def write(self, new_content):
        """Overwrite the file with new contents and update its created time.

        Creates the containing directories if needed.
        """
        ensure_directory(os.path.dirname(self.get_path()))
        write_content_to_file(new_content, self.get_path())
        self.created = time.time()
コード例 #3
0
    def execute_with_point_of_entry_and_assert(self, id):
        expected_result = read_data("%s_output.py" % id)
        project = ProjectInDirectory(self.tmpdir).with_points_of_entry(["poe.py"])
        module_path = putfile(project.path, "module.py", read_data("%s_module.py" % id))
        write_content_to_file(read_data("generic_acceptance_poe.py"), project.path_for_point_of_entry("poe.py"))

        inspect_project(project)
        add_tests_to_project(project, [module_path], 'unittest')
        result = get_test_module_contents(project)

        assert_equal_strings(expected_result, result)
コード例 #4
0
ファイル: test_acceptance.py プロジェクト: Br3nda/pythoscope
    def execute_with_point_of_entry_and_assert(self, id):
        expected_result = read_data("%s_output.py" % id)
        project = ProjectInDirectory(self.tmpdir).with_points_of_entry(["poe.py"])
        module_path = putfile(project.path, "module.py", read_data("%s_module.py" % id))
        write_content_to_file(read_data("generic_acceptance_poe.py"), project.path_for_point_of_entry("poe.py"))

        inspect_project(project)
        add_tests_to_project(project, [module_path], 'unittest')
        result = get_test_module_contents(project)

        assert_equal_strings(expected_result, result)
コード例 #5
0
 def test_rewrites_modules_during_import(self):
     tmpdir = tempfile.mkdtemp()
     write_content_to_file("abs(-2)", os.path.join(tmpdir, 'mod.py'))
     sys.path.insert(0, tmpdir)
     try:
         def fun():
             import mod
         self.trace_function(fun)
         self.assert_trace(('c_call', (abs, [-2], {})),
                           ('c_return', 2))
     finally:
         shutil.rmtree(tmpdir)
コード例 #6
0
    def test_rewrites_modules_during_import(self):
        tmpdir = tempfile.mkdtemp()
        write_content_to_file("abs(-2)", os.path.join(tmpdir, 'mod.py'))
        sys.path.insert(0, tmpdir)
        try:

            def fun():
                import mod

            self.trace_function(fun)
            self.assert_trace(('c_call', (abs, [-2], {})), ('c_return', 2))
        finally:
            shutil.rmtree(tmpdir)
コード例 #7
0
ファイル: store.py プロジェクト: goulu/pythoscope
    def save(self):
        # To avoid inconsistencies try to save all project's modules first. If
        # any of those saves fail, the pickle file won't get updated.
        for module in self.get_modules():
            log.debug("Calling save() on module %r" % module.subpath)
            module.save()

        # We don't want to have a single AST in a Project instance.
        self.code_trees_manager.clear_cache()

        # Pickling the project after saving all of its modules, so any changes
        # made by Module instances during save() will be preserved as well.
        pickled_project = pickle.dumps(self)

        log.debug("Writing project pickle to disk...")
        write_content_to_file(pickled_project, self._get_pickle_path(), binary=True)
コード例 #8
0
ファイル: store.py プロジェクト: jmikedupont2/pythoscope
    def save(self):
        # To avoid inconsistencies try to save all project's modules first. If
        # any of those saves fail, the pickle file won't get updated.
        for module in self.get_modules():
            log.debug("Calling save() on module %r" % module.subpath)
            module.save()

        # We don't want to have a single AST in a Project instance.
        self.code_trees_manager.clear_cache()

        # Pickling the project after saving all of its modules, so any changes
        # made by Module instances during save() will be preserved as well.
        pickled_project = pickle.dumps(self)

        log.debug("Writing project pickle to disk...")
        write_content_to_file(pickled_project,
                              self._get_pickle_path(),
                              binary=True)
コード例 #9
0
ファイル: store.py プロジェクト: jmikedupont2/pythoscope
 def save(self, path):
     """Pickle and save this CodeTree under given path.
     """
     pickled_code_tree = pickle.dumps(self)
     write_content_to_file(pickled_code_tree, path, binary=True)
コード例 #10
0
ファイル: helper.py プロジェクト: jmikedupont2/pythoscope
def putfile(directory, filename, contents):
    filepath = os.path.join(directory, filename)
    mkdirs(os.path.dirname(filepath))
    write_content_to_file(contents, filepath)
    return filepath
コード例 #11
0
ファイル: store.py プロジェクト: goulu/pythoscope
 def save(self, path):
     """Pickle and save this CodeTree under given path.
     """
     pickled_code_tree = pickle.dumps(self)
     write_content_to_file(pickled_code_tree, path, binary=True)