示例#1
0
文件: test_cast.py 项目: rec/scripta
 def test_error(self):
     cast = Cast()
     cast.append('ls -cail', 1)
     with self.assertRaises(ValueError):
         cast.extend(cast, -2)
     with self.assertRaises(ValueError):
         cast.append('hello', -2)
示例#2
0
文件: test_cast.py 项目: rec/scripta
def _round_trip(cast):
    s = io.StringIO()
    cast.write(s)

    s.seek(0)
    cast2 = Cast.read(s)
    assert cast.lines == cast2.lines
    assert cast.header == cast2.header
示例#3
0
文件: test_cast.py 项目: rec/scripta
 def test_keystroke_times(self):
     cast = Cast.read(open(TEST_CAST_FILE))
     actual = list(cast.keystroke_times())
     for t in actual:
         print('%s,' % round(t, 3))
     expected = []
     assert len(actual) == 48
     expected = [0.279, 0.177, 0.104, 0.248, 0.103, 0.08, 0.186, 0.224]
     assert [round(i, 3) for i in actual[:8]] == expected
示例#4
0
文件: test_cast.py 项目: rec/scripta
    def test_append_time_zero(self):
        cast = Cast()
        cast.append('ls -cail', 1)
        cast.append('', 2.5)
        cast.append(' frog', 0.5)

        _round_trip(cast)
        expected = [
            [1, 'o', 'ls -cail'],
            [4, 'o', ' frog'],
        ]
        assert [i.to_list() for i in cast.lines] == expected
示例#5
0
文件: test_cast.py 项目: rec/scripta
 def test_scale(self):
     cast = Cast()
     cast.append('ls -cail', 1)
     cast.extend(cast, 2)
     cast.extend(cast, 4)
     cast.scale_by(2)
     expected = [
         [2, 'o', 'ls -cail'],
         [8, 'o', 'ls -cail'],
         [18, 'o', 'ls -cail'],
         [24, 'o', 'ls -cail'],
     ]
     assert [i.to_list() for i in cast.lines] == expected
示例#6
0
    async def test_bash(self):
        with tdir({'test.sh': 'echo HELLO\npwd\n'}):
            await CastRecorder('test.sh').record_to('test.cast')
            Cast.read('test.cast').write('/code/scripta/test/test.cast')

            actual = [i.chars for i in Cast.read('test.cast').lines]
            expected = [
                constants.CONTROL_L,
                BASH_PS[0],
                '3',
                constants.BACKSPACE,
                'e',
                'c',
                'h',
                'o',
                ' ',
                'N',
                constants.BACKSPACE,
                'H',
                'E',
                'l',
                constants.BACKSPACE,
                'L',
                'L',
                'O',
                '\r\n',
                'HELLO\r\n',
                BASH_PS[0],
                'p',
                'w',
                'd',
                '\r\n',
                os.getcwd() + '\r\n',
                BASH_PS[0],
            ]
            if actual != expected:
                print(*actual, sep='\n')
            assert actual == expected
示例#7
0
 async def test_record_python(self):
     with tdir({'test.py': TEST_PY}):
         await CastRecorder('test.py').record_to('test.cast')
         actual = [i.chars for i in Cast.read('test.cast').lines]
         expected = [
             '\x1b[H\x1b[2J',
             '>>> ',
             '\r\n',
             'p',
             'r',
             'i',
             'n',
             't',
             '9',
             constants.BACKSPACE,
             '(',
             "'",
             'h',
             'e',
             'l',
             'l',
             'o',
             "'",
             '0',
             constants.BACKSPACE,
             ')',
             '\r\n',
             'hello\r\n',
             '>>> ',
             'i',
             'm',
             'p',
             'o',
             'r',
             'T',
             constants.BACKSPACE,
             't',
             ' ',
             'o',
             's',
             '\r\n',
             '>>> ',
             'O',
             constants.BACKSPACE,
             'o',
             's',
             '.',
             'g',
             'e',
             't',
             'c',
             's',
             constants.BACKSPACE,
             'w',
             'd',
             '(',
             ')',
             '\r\n',
             "'%s'\r\n" % os.getcwd(),
             '>>> ',
         ]
         if actual != expected:
             print(*actual, sep='\n')
         assert actual == expected
示例#8
0
文件: test_cast.py 项目: rec/scripta
 def test_extend(self):
     cast1 = Cast()
     cast1.append('ls -cail', 1)
     cast = Cast()
     cast.extend(cast)
     assert not cast.lines
示例#9
0
文件: test_cast.py 项目: rec/scripta
 def test_epsilon(self):
     cast = Cast()
     cast.append('ls -cail', EPSILON / 2)
     assert cast.lines[0].time == 0
示例#10
0
文件: test_cast.py 项目: rec/scripta
 def test_simple(self):
     cast = Cast()
     cast.append('ls -cail', 1)
     _round_trip(cast)
示例#11
0
文件: test_cast.py 项目: rec/scripta
 def test_empty(self):
     cast = Cast()
     _round_trip(cast)