예제 #1
0
파일: test_usage.py 프로젝트: aytel/honor18
    def test_octave_class(self):
        self.oc.addpath(os.path.realpath(os.path.dirname(__file__)))
        polynomial = self.oc.polynomial
        p0 = polynomial([1, 2, 3])
        assert np.allclose(p0.poly, [[1, 2, 3]])

        p1 = polynomial([0, 1, 2])
        sobj = StringIO()
        hdlr = logging.StreamHandler(sobj)
        hdlr.setLevel(logging.DEBUG)
        self.oc.logger.addHandler(hdlr)
        self.oc.logger.setLevel(logging.DEBUG)
        p1.display(verbose=True, nout=0)
        text = hdlr.stream.getvalue().strip()
        self.oc.logger.removeHandler(hdlr)
        assert 'in poly display' in text

        self.oc.push('y', p0)
        p2 = self.oc.pull('y')
        assert np.allclose(p2.poly, [1, 2, 3])

        p2.poly = [2, 3, 4]
        assert np.allclose(p2.poly, [2, 3, 4])

        assert 'Display a polynomial object' in p2.display.__doc__

        self.oc.eval('p3 = polynomial([1,2,3])')
        p3 = self.oc.pull('p3')
        assert np.allclose(p3.poly, [1, 2, 3])
예제 #2
0
    def test_deprecated_log(self):
        sobj = StringIO()
        hdlr = logging.StreamHandler(sobj)
        hdlr.setLevel(logging.DEBUG)
        self.oc.logger.addHandler(hdlr)

        self.oc.logger.setLevel(logging.DEBUG)
        self.oc.eval('disp("hi")', log=False)
        text = hdlr.stream.getvalue().strip()
        assert not text
        self.oc.logger.removeHandler(hdlr)
예제 #3
0
파일: test_oct2py.py 프로젝트: minrk/oct2py
def test_keyboard():

    oc = Oct2Py()

    oc._eval('a=1')

    stdin = sys.stdin
    stdout = sys.stdout
    output = StringIO()
    sys.stdin = StringIO('a\nreturn')
    oc._session.stdout = output
    try:
        oc.keyboard(timeout=3)
    except Oct2PyError as e:
        if 'session timed out' in str(e).lower():
            return
    sys.stdin.flush()
    sys.stdin = stdin
    oc._session.stdout = stdout

    out = output.getvalue()
    assert 'Entering Octave Debug Prompt...' in out
    assert 'a =  1' in out
예제 #4
0
def test_keyboard():

    oc = Oct2Py()

    oc._eval('a=1')

    stdin = sys.stdin
    stdout = sys.stdout
    output = StringIO()
    sys.stdin = StringIO('a\nreturn')
    oc._session.stdout = output
    try:
        oc.keyboard(timeout=3)
    except Oct2PyError as e:
        if 'session timed out' in str(e).lower():
            return
    sys.stdin.flush()
    sys.stdin = stdin
    oc._session.stdout = stdout

    out = output.getvalue()
    assert 'Entering Octave Debug Prompt...' in out
    assert 'a =  1' in out
예제 #5
0
    def test_keyboard(self):
        self.oc.eval('a=1')

        stdin = sys.stdin
        stdout = sys.stdout
        output = StringIO()
        sys.stdin = StringIO('a\nexit')
        self.oc._session.stdout = output
        try:
            self.oc.keyboard(timeout=3)
        except Oct2PyError as e:  # pragma: no cover
            if 'session timed out' in str(e).lower():
                # the keyboard command is not supported
                # (likely using Octave 3.2)
                return
            else:
                raise(e)
        sys.stdin.flush()
        sys.stdin = stdin
        self.oc._session.stdout = stdout

        out = output.getvalue()
        assert 'Entering Octave Debug Prompt...' in out
        assert 'a =  1' in out
예제 #6
0
파일: test_misc.py 프로젝트: suever/oct2py
    def test_keyboard(self):
        self.oc.eval('a=1')

        stdin = sys.stdin
        stdout = sys.stdout
        output = StringIO()
        sys.stdin = StringIO('a\nexit')
        self.oc._session.stdout = output
        try:
            self.oc.keyboard(timeout=3)
        except Oct2PyError as e:  # pragma: no cover
            if 'session timed out' in str(e).lower():
                # the keyboard command is not supported
                # (likely using Octave 3.2)
                return
            else:
                raise(e)
        sys.stdin.flush()
        sys.stdin = stdin
        self.oc._session.stdout = stdout

        out = output.getvalue()
        assert 'Entering Octave Debug Prompt...' in out
        assert 'a =  1' in out
예제 #7
0
파일: test_misc.py 프로젝트: suever/oct2py
    def test_multiline_statement(self):
        sobj = StringIO()
        hdlr = logging.StreamHandler(sobj)
        hdlr.setLevel(logging.DEBUG)
        self.oc.logger.addHandler(hdlr)

        self.oc.logger.setLevel(logging.DEBUG)

        ans = self.oc.eval("""
    a =1
    a + 1;
    b = 3
    b + 1""")
        text = hdlr.stream.getvalue().strip()
        assert ans == 4
        assert text.endswith('\na =  1\nb =  3\nans =  4')
예제 #8
0
    def test_multiline_statement(self):
        sobj = StringIO()
        hdlr = logging.StreamHandler(sobj)
        hdlr.setLevel(logging.DEBUG)
        self.oc.logger.addHandler(hdlr)

        self.oc.logger.setLevel(logging.DEBUG)

        ans = self.oc.eval("""
    a =1
    a + 1;
    b = 3
    b + 1""")
        text = hdlr.stream.getvalue().strip()
        self.oc.logger.removeHandler(hdlr)
        assert ans == 4
        lines = text.splitlines()
        assert lines[-1] == 'ans =  4'
        assert lines[-2] == 'b =  3'
        assert lines[-3] == 'a =  1'
예제 #9
0
파일: test_misc.py 프로젝트: suever/oct2py
 def get_handler():
     sobj = StringIO()
     hdlr = logging.StreamHandler(sobj)
     hdlr.setLevel(logging.DEBUG)
     return hdlr