Beispiel #1
0
def setUp(test):
    setupstack.setUpDirectory(test)
    zc.zk.testing.setUp(test, tree='/databases\n  /demo\n')

    # The original server loop spews thread exceptions during shutdowm.
    # This version doesn't.
    from ZEO.zrpc.connection import server_loop as _server_loop
    def server_loop(map):
        try:
            _server_loop(map)
        except Exception:
            if len(map) > 1:
                raise

    setupstack.context_manager(
        test, mock.patch('ZEO.zrpc.connection.server_loop')
        ).side_effect = server_loop

    setupstack.context_manager(
        test, mock.patch('netifaces.interfaces')).return_value = ['iface']

    globs = test.globs
    globs['ifaddress'] = '1.2.3.4'
    setupstack.context_manager(
        test, mock.patch('netifaces.ifaddresses',
                         lambda i: {2: [dict(addr=globs['ifaddress'])]}
                         ))

    del zc.zk.monitor._servers[:]
Beispiel #2
0
Datei: testing.py Projekt: zc/sqs
def setUp(test):
    setupstack.setUpDirectory(test)
    test.globs['sqs_queues'] = queues = Queues()
    setupstack.context_manager(
        test,
        mock.patch("boto.sqs.connect_to_region",
                   side_effect=queues.connect_to_region))
Beispiel #3
0
def setUpFile(test):
    setupstack.setUpDirectory(test)
    zc.zk.testing.setUp(test)
    test.globs['now'] = 1380541206.52
    def time():
        return test.globs['now']
    setupstack.context_manager(test, mock.patch("time.time", side_effect=time))
Beispiel #4
0
def setUpFile(test):
    setupstack.setUpDirectory(test)
    zc.zk.testing.setUp(test)
    test.globs['now'] = 1380541206.52

    def time():
        return test.globs['now']

    setupstack.context_manager(test, mock.patch("time.time", side_effect=time))
Beispiel #5
0
def setUp(test):
    setupstack.setUpDirectory(test)
    dt = setupstack.context_manager(test, mock.patch("datetime.datetime"))
    dt.now = lambda: Metric.end
    setupstack.context_manager(
        test,
        mock.patch("boto.ec2.cloudwatch.connect_to_region",
                   side_effect=Connection),
    )
def setUp(test):
    setupstack.setUpDirectory(test)
    getpwname = setupstack.context_manager(test, mock.patch('pwd.getpwnam'))
    getpwname.return_value = O(pw_gid=5, pw_uid=99, pw_name='zope')
    setupstack.context_manager(test, mock.patch('os.geteuid')).return_value = 0
    setupstack.context_manager(test, mock.patch('grp.getgrall'))
    setupstack.context_manager(test, mock.patch('os.setgroups'))
    setupstack.context_manager(test, mock.patch('os.setuid'))
    setupstack.context_manager(test, mock.patch('os.setgid'))
Beispiel #7
0
def setUp(test):
    setupstack.setUpDirectory(test)
    setupstack.context_manager(
        test, mock.patch.dict(os.environ, HOME=os.getcwd()))
    setupstack.context_manager(
        test,
        mock.patch('keyring.get_password',
                   side_effect=lambda name, login: name+login+'pw')
        )
Beispiel #8
0
def setUp(test):
    setupstack.setUpDirectory(test)
    getpwname = setupstack.context_manager(test, mock.patch('pwd.getpwnam'))
    getpwname.return_value = O(pw_gid=5, pw_uid=99, pw_name='zope')
    setupstack.context_manager(test, mock.patch('os.geteuid')).return_value = 0
    setupstack.context_manager(test, mock.patch('grp.getgrall'))
    setupstack.context_manager(test, mock.patch('os.setgroups'))
    setupstack.context_manager(test, mock.patch('os.setuid'))
    setupstack.context_manager(test, mock.patch('os.setgid'))
Beispiel #9
0
def setUp(test):
    setupstack.setUpDirectory(test)
    getpwname = setupstack.context_manager(test, mock.patch("pwd.getpwnam"))
    getpwname.return_value = O(pw_gid=5, pw_uid=99, pw_name="zope")
    setupstack.context_manager(test, mock.patch("os.geteuid")).return_value = 0
    setupstack.context_manager(test, mock.patch("grp.getgrall"))
    setupstack.context_manager(test, mock.patch("os.setgroups"))
    setupstack.context_manager(test, mock.patch("os.setuid"))
    setupstack.context_manager(test, mock.patch("os.setgid"))
Beispiel #10
0
def setUp(test):
    setupstack.setUpDirectory(test)

    for i in ('1', '2'):
        name = 'testmodule'+i
        module = types.ModuleType('bobo.'+name)
        setattr(bobo, name, module)
        sys.modules[module.__name__] = module
        setupstack.register(test, delattr, bobo, name)
        setupstack.register(test, sys.modules.__delitem__, module.__name__)
Beispiel #11
0
def setUpClient(test):
    setupstack.setUpDirectory(test)
    def print_bytes(bytes):
        print '_check_blob_size(%s)' % bytes
    setupstack.context_manager(
        test,
        mock.patch("ZEO.ClientStorage.ClientStorage._check_blob_size",
                   side_effect = print_bytes),
        )
    zc.zk.testing.setUp(test)
Beispiel #12
0
def setUp(test):
    setupstack.setUpDirectory(test)

    for i in ('1', '2'):
        name = 'testmodule'+i
        module = types.ModuleType('bobo.'+name)
        setattr(bobo, name, module)
        sys.modules[module.__name__] = module
        setupstack.register(test, delattr, bobo, name)
        setupstack.register(test, sys.modules.__delitem__, module.__name__)
Beispiel #13
0
def setup_intro(test):
    setupstack.setUpDirectory(test)

    def update_module(name, src):
        if name not in sys.modules:
            sys.modules[name] = types.ModuleType(name)
            setupstack.register(test, sys.modules.__delitem__, name)
        module = sys.modules[name]
        six.exec_(src, module.__dict__)

    test.globs['update_module'] = update_module
Beispiel #14
0
def setup_intro(test):
    setupstack.setUpDirectory(test)

    def update_module(name, src):
        if name not in sys.modules:
            sys.modules[name] = types.ModuleType(name)
            setupstack.register(test, sys.modules.__delitem__, name)
        module = sys.modules[name]
        exec src in module.__dict__

    test.globs['update_module'] = update_module
Beispiel #15
0
def setUpClient(test):
    setupstack.setUpDirectory(test)

    def print_bytes(bytes):
        print '_check_blob_size(%s)' % bytes

    setupstack.context_manager(
        test,
        mock.patch("ZEO.ClientStorage.ClientStorage._check_blob_size",
                   side_effect=print_bytes),
    )
    zc.zk.testing.setUp(test)
Beispiel #16
0
def setUp(test):

    test.globs['tmp_dir'] = tempfile.mkdtemp()

    this_directory = os.path.split(__file__)[0]
    directory_with_tests = os.path.join(this_directory, 'src')
    test.globs['defaults'] = ['--path', directory_with_tests,
                              '--tests-pattern', '^sampletests$']

    setupstack.setUpDirectory(test)

    test.globs['reports_dir'] = os.path.join(
        os.path.join(os.getcwd(), 'reports'))
Beispiel #17
0
def setUp(test):
    setUpPP(test)
    setupstack.setUpDirectory(test)
    with open(os.path.join(os.path.dirname(__file__), 'filecheck_py')) as src:
        with open('filecheck.py', 'w') as dest:
            dest.write(src.read())

    setupstack.context_manager(
        test, mock.patch('socket.getfqdn', return_value='test.example.com'))

    global meta_db
    meta_db = zc.cimaa.stub.MemoryDB({})
    setupstack.context_manager(test,
                               mock.patch('getpass.getuser', lambda: 'tester'))
Beispiel #18
0
def setUp(test):
    setupstack.setUpDirectory(test)
    connect_to_region = setupstack.context_manager(
        test, mock.patch('boto.cloudformation.connect_to_region'))

    regions = ()
    connections = {}
    for name in 'us-f12g', 'us-manassas':
        regions += (Region(name), )
        connections[name] = CloudFormationConnection(regions[-1])

    test.globs['connections'] = connections

    @side_effect(
        setupstack.context_manager(
            test, mock.patch('boto.cloudformation.connect_to_region')))
    def _(region_name):
        print 'connecting to', region_name
        return connections[region_name]

    setupstack.context_manager(
        test,
        mock.patch('boto.cloudformation.regions', side_effect=lambda: regions))

    @side_effect(
        setupstack.context_manager(test,
                                   mock.patch('boto.ec2.connect_to_region')))
    def _(region_name):
        if region_name != 'us-f12g':
            raise AssertionError
        return EC2Connection()

    test.globs['writefile'] = writefile

    setupstack.context_manager(test, mock.patch('logging.basicConfig'))
    setupstack.context_manager(test, mock.patch('time.sleep'))
Beispiel #19
0
def setUp(test):
    cleanup()
    setupstack.setUpDirectory(test)
    setupstack.register(test, cleanup)
Beispiel #20
0
def setUp(test):
    setupstack.setUpDirectory(test)
Beispiel #21
0
def setUp(test):
    cleanup()
    setupstack.setUpDirectory(test)
    setupstack.register(test, cleanup)