Esempio n. 1
0
def setup_module(module):
    global c, f, d, n
    if IS_MAC:  # the 32-bit server for Mac OS does not exist
        return
    c = Cpp64()
    f = Fortran64()
    d = Echo64(True)
    n = DotNet64()
Esempio n. 2
0
def test_unclosed_warnings_2(recwarn):
    for _ in range(3):
        cpp = Cpp64()
        out, err = cpp.shutdown_server32()
        for _ in range(10):
            out.close()
            err.close()
        del cpp
    gc.collect()
    assert len(recwarn) == 0
Esempio n. 3
0
def setup_module():
    global c, f, e, n
    if IS_MAC:  # the 32-bit server for macOS does not exist
        return
    c = Cpp64()
    f = Fortran64()
    e = Echo64()
    if IS_WINDOWS:
        # stop testing on 64-bit linux because Mono can load
        # both 32-bit and 64-bit libraries
        n = DotNet64()
Esempio n. 4
0
def test_unclosed_warnings_1(recwarn):
    # recwarn is a built-in pytest fixture that records all warnings emitted by test functions

    # The following warnings should not be written to stderr for the unclosed subprocess PIPE's
    #   sys:1: ResourceWarning: unclosed file <_io.BufferedReader name=3>
    #   sys:1: ResourceWarning: unclosed file <_io.BufferedReader name=4>
    # nor for unclosed sockets
    #   ResourceWarning: unclosed <socket.socket ...>

    Cpp64()
    gc.collect()
    assert len(recwarn) == 0
Esempio n. 5
0
def test_client():
    with Cpp64() as cpp:
        assert cpp.connection is not None
        assert cpp.add(1, -1) == 0
    assert cpp.connection is None

    # can still call this (even multiple times)
    for _ in range(10):
        out, err = cpp.shutdown_server32()
        assert out.closed
        assert err.closed

    with Cpp64() as cpp:
        out, err = cpp.shutdown_server32()
        assert not out.closed
        assert not err.closed
        assert out.read() == b''
        assert err.read() == b''
    out, err = cpp.shutdown_server32()
    assert out.closed
    assert err.closed

    assert 'lib=None address=None' in str(cpp)
    assert 'lib=None address=None' in repr(cpp)
Esempio n. 6
0
import os
import pytest

from msl import loadlib
from msl.examples.loadlib import Cpp64, Fortran64, Dummy64

eps = 1e-10

c = Cpp64()
f = Fortran64()
d = Dummy64(True)


def teardown_module(module):
    c.shutdown_server()
    f.shutdown_server()
    d.shutdown_server()


def test_unique_ports():
    for item in [f, d]:
        assert c.port != item.port
    for item in [c, d]:
        assert f.port != item.port
    for item in [c, f]:
        assert d.port != item.port


def test_lib_name():
    def get_name(path):
        return os.path.basename(path).split('.')[0]
Esempio n. 7
0
"""
Checks that running a script with pythonw.exe does not
1) create a new console
2) the console that pythonw.exe is executing on does not "flash"
"""
import os
import sys

# make sure that msl.loadlib is importable
path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
sys.path.insert(0, path)

from msl.loadlib import LoadLibrary
from msl.examples.loadlib import (
    EXAMPLES_DIR,
    Cpp64,
)

if os.path.basename(sys.executable) != 'pythonw.exe':
    raise RuntimeError('Must run this script using,\n'
                       '  pythonw.exe ' + __file__)

with LoadLibrary(os.path.join(EXAMPLES_DIR, 'Trig.class')) as java:
    pass

with Cpp64():
    pass