Exemplo n.º 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)
Exemplo n.º 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')
Exemplo n.º 3
0
def mock_io(mocker):
    replace_builtins()
Exemplo n.º 4
0
def mock_io(mocker):
    replace_builtins()
Exemplo n.º 5
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()