예제 #1
0
    def test_patching(self):
        storage.replace_builtins()
        try:
            self.assertEqual(__builtin__.file, storage.file)
            self.assertEqual(__builtin__.open, storage.open)
        finally:
            storage.restore_builtins()

        self.assertEqual(__builtin__.file, storage.original_file)
        self.assertNotEqual(storage.original_file, storage.file)
        self.assertEqual(__builtin__.open, storage.original_open)
        self.assertNotEqual(storage.original_open, storage.open)
예제 #2
0
from System.Windows.Controls import (HyperlinkButton, ComboBoxItem,
                                     Orientation, StackPanel, TextBlock)
from System.Windows.Markup import XamlReader
from System.Windows.Media import FontFamily

from consoletextbox import ConsoleTextBox
from context import context, title
from mousehandler import MouseHandler
from printer import StatefulPrinter
from utils import always_invoke, _debug, SetInvokeRoot, load_document

import storage
import storage_backend
from storage import original_open as open
storage.backend = storage_backend
storage.replace_builtins()

# create the example files
if not storage_backend.CheckForFile('myfile.txt'):
    h = storage.open('myfile.txt', 'w')
    h.write("""This is a text file.
    You can read it.
    It exists.
    """)
    h.close()
if not storage_backend.CheckForFile('workfile'):
    h = storage.open('workfile', 'w')
    h.write('This is the entire file.\n')
    h.close()
if not storage_backend.CheckForFile('workfile2'):
    h = storage.open('workfile2', 'w')
예제 #3
0
파일: io.py 프로젝트: yodermk/holland
def mock_io(mocker):
    replace_builtins()
예제 #4
0
def mock_io(mocker):
    replace_builtins()
예제 #5
0
파일: main.py 프로젝트: gozack1/trypython
from System.Windows.Controls import HyperlinkButton, ComboBoxItem, Orientation, StackPanel, TextBlock
from System.Windows.Markup import XamlReader
from System.Windows.Media import FontFamily

from consoletextbox import ConsoleTextBox
from context import context, title
from mousehandler import MouseHandler
from printer import StatefulPrinter
from utils import always_invoke, _debug, SetInvokeRoot, load_document

import storage
import storage_backend
from storage import original_open as open

storage.backend = storage_backend
storage.replace_builtins()

# create the example files
if not storage_backend.CheckForFile("myfile.txt"):
    h = storage.open("myfile.txt", "w")
    h.write(
        """This is a text file.
    You can read it.
    It exists.
    """
    )
    h.close()
if not storage_backend.CheckForFile("workfile"):
    h = storage.open("workfile", "w")
    h.write("This is the entire file.\n")
    h.close()