summaryrefslogtreecommitdiff
path: root/pexpect/tests/test_ansi.py
blob: 1179200a2e01712d0e64e4f727adc26bc9c9c074 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python

import ANSI
import unittest
import PexpectTestCase

write_target = 'I\'ve got a ferret sticking up my nose.                           \n' +\
'(He\'s got a ferret sticking up his nose.)                        \n' +\
'How it got there I can\'t tell                                    \n' +\
'But now it\'s there it hurts like hell                            \n' +\
'And what is more it radically affects my sense of smell.         \n' +\
'(His sense of smell.)                                            '

write_text = 'I\'ve got a ferret sticking up my nose.\n' + \
'(He\'s got a ferret sticking up his nose.)\n' + \
'How it got there I can\'t tell\n' + \
'But now it\'s there it hurts like hell\n' + \
'And what is more it radically affects my sense of smell.\n' + \
'(His sense of smell.)\n' + \
'I can see a bare-bottomed mandril.\n' + \
'(Slyly eyeing his other nostril.)\n' + \
'If it jumps inside there too I really don\'t know what to do\n' + \
'I\'ll be the proud posessor of a kind of nasal zoo.\n' + \
'(A nasal zoo.)\n' + \
'I\'ve got a ferret sticking up my nose.\n' + \
'(And what is worst of all it constantly explodes.)\n' + \
'"Ferrets don\'t explode," you say\n' + \
'But it happened nine times yesterday\n' + \
'And I should know for each time I was standing in the way.\n' + \
'I\'ve got a ferret sticking up my nose.\n' + \
'(He\'s got a ferret sticking up his nose.)\n' + \
'How it got there I can\'t tell\n' + \
'But now it\'s there it hurts like hell\n' + \
'And what is more it radically affects my sense of smell.\n' + \
'(His sense of smell.)'

tetris_target='                           XX            XXXX    XX                             \n' +\
'                           XXXXXX    XXXXXXXX    XX                             \n' +\
'                           XXXXXX    XXXXXXXX    XX                             \n' +\
'                           XX  XX    XX  XXXX    XX                             \n' +\
'                           XXXXXX  XXXX  XXXX    XX                             \n' +\
'                           XXXXXXXXXX    XXXX    XX                             \n' +\
'                           XX  XXXXXX      XX    XX                             \n' +\
'                           XXXXXX          XX    XX                             \n' +\
'                           XXXX    XXXXXX  XX    XX                             \n' +\
'                           XXXXXX    XXXX  XX    XX                             \n' +\
'                           XX  XX    XXXX  XX    XX                             \n' +\
'                           XX  XX      XX  XX    XX                             \n' +\
'                           XX  XX    XXXX  XXXX  XX                             \n' +\
'                           XXXXXXXX  XXXX  XXXX  XX                             \n' +\
'                           XXXXXXXXXXXXXX  XXXXXXXX                             \n' +\
'                           XX    XXXXXXXX  XX    XX                             \n' +\
'                           XXXXXXXXXXXXXX  XX    XX                             \n' +\
'                           XX  XXXX    XXXXXX    XX                             \n' +\
'                           XXXXXX          XXXXXXXX                             \n' +\
'                           XXXXXXXXXX      XX    XX                             \n' +\
'                           XXXXXXXXXXXXXXXXXXXXXXXX                             \n' +\
'                                                                                \n' +\
'  J->LEFT  K->ROTATE  L->RIGHT  SPACE->DROP  P->PAUSE  Q->QUIT                  \n' +\
'                                                                                '

torture_target='+--------------------------------------------------------------------------------+\n' +\
'|a`opqrs`      This is the       `srqpo`a                                        |\n' +\
'|VT100 series Torture Test Demonstration.                                        |\n' +\
'|VT100 series Torture Test Demonstration.                                        |\n' +\
'|This is a normal line __________________________________________________y_      |\n' +\
'|This is a bold line (normal unless the Advanced Video Option is installed)      |\n' +\
'|This line is underlined _ "       "       "       "       "       "    _y_      |\n' +\
'|This is a blinking line _ "       "       "       "       "       "    _y_      |\n' +\
'|This is inverse video _ (underlined if no AVO and cursor is underline) _y_      |\n' +\
'|Normal gjpqy Underline   Blink   Underline+Blink gjpqy                          |\n' +\
'|Bold   gjpqy Underline   Blink   Underline+Blink gjpqy                          |\n' +\
'|Inverse      Underline   Blink   Underline+Blink                                |\n' +\
'|Bold+Inverse Underline   Blink   Underline+Blink                                |\n' +\
'|This is double width                                                            |\n' +\
'|This is double height                                                           |\n' +\
'|This is double height                                                           |\n' +\
'|_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ioy                                        |\n' +\
'|_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ioy                                        |\n' +\
'|_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ioy                                        |\n' +\
'|`abcdefghijklmnopqrstuvwxyz{|}~ lqwqk                                           |\n' +\
'|`abcdefghijklmnopqrstuvwxyz{|}~ tqnqu                                           |\n' +\
'|`abcdefghijklmnopqrstuvwxyz{|}~ tqnqu                                           |\n' +\
'|`abcdefghijklmnopqrstuvwxyz{|}~ mqvqj                                           |\n' +\
'|   This test created by Joe Smith, 8-May-85                                     |\n' +\
'|                                                                                |\n' +\
'+--------------------------------------------------------------------------------+\n'

class ansiTestCase (PexpectTestCase.PexpectTestCase):
    def test_write (self):
        s = ANSI.ANSI (6,65)
        s.fill('.')
        s.cursor_home()
        for c in write_text:
            s.write (c)
        assert str(s) == write_target
    def test_torturet (self):
        s = ANSI.ANSI (24,80)
        sample_text = open ('torturet.vt').read()
        for c in sample_text:
            s.process (c)
        assert s.pretty() == torture_target, 'processed: \n' + s.pretty() + '\nexpected:\n' + torture_target
    def test_tetris (self):
        s = ANSI.ANSI (24,80)
        tetris_text = open ('tetris.data').read()
        for c in tetris_text:
            s.process (c)
        assert str(s) == tetris_target

if __name__ == '__main__':
    unittest.main()

suite = unittest.makeSuite(ansiTestCase,'test')