mirror of
https://github.com/clearml/wexpect-venv
synced 2025-01-31 02:46:59 +00:00
[ADD] long read testcases against fixed #10
This commit is contained in:
parent
f9b6ee08a4
commit
73fa299475
72
tests/long_printer.py
Normal file
72
tests/long_printer.py
Normal file
@ -0,0 +1,72 @@
|
||||
'''
|
||||
This is is a very basic stdio handler script. This is used by python.py example.
|
||||
'''
|
||||
|
||||
import time
|
||||
|
||||
puskas_wiki = ['''Ferenc Puskas was a Hungarian footballer and manager, widely regarded as one of \
|
||||
the greatest players of all time. He is the son of former footballer Ferenc Puskas Senior. A \
|
||||
prolific forward, he scored 84 goals in 85 international matches for Hungary, played 4 \
|
||||
international matches for Spain and scored 514 goals in 529 matches in the Hungarian and Spanish \
|
||||
leagues. He became an Olympic champion in 1952 and led his nation to the final of the 1954 World \
|
||||
Cup where he was named the tournament's best player. He won three European Cups (1959, 1960, 1966),\
|
||||
10 national championships (5 Hungarian and 5 Spanish Primera Division) and 8 top individual \
|
||||
scoring honors. In 1995, he was recognized as the top scorer of the 20th century by the IFFHS.''',
|
||||
'''Puskas started his career in Hungary playing for Kispest and Budapest Honved. He was the top scorer\
|
||||
in the Hungarian League on four occasions, and in 1948, he was the top goal scorer in Europe. \
|
||||
During the 1950s, he was both a prominent member and captain of the Hungarian national team, known\
|
||||
as the Mighty Magyars. In 1958, two years after the Hungarian Revolution, he emigrated to Spain \
|
||||
where he played for Real Madrid. While playing with Real Madrid, Puskas won four Pichichis and \
|
||||
scored seven goals in two European Champions Cup finals.''',
|
||||
'''After retiring as a player, he became a coach. The highlight of his coaching career came in 1971 \
|
||||
when he guided Panathinaikos to the European Cup final, where they lost 2-0 to AFC Ajax. In 1993, \
|
||||
he returned to Hungary and took temporary charge of the Hungarian national team. In 1998, he \
|
||||
became one of the first ever FIFA/SOS Charity ambassadors. In 2002, the Nepstadion in Budapest \
|
||||
was renamed the Puskas Ferenc Stadion in his honor. He was also declared the best Hungarian \
|
||||
player of the last 50 years by the Hungarian Football Federation in the UEFA Jubilee Awards in \
|
||||
November 2003. In October 2009, FIFA announced the introduction of the FIFA Puskas Award, \
|
||||
awarded to the player who has scored the "most beautiful goal" over the past year. He was also \
|
||||
listed in Pele's FIFA 100.''',
|
||||
'''Ferenc Purczeld was born on 2 April 1927 to a German (Danube Swabian) family in Budapest and \
|
||||
brought up in Kispest, then a suburb, today part of the city. His mother, Margit Biro \
|
||||
(1904-1976), was a seamstress. He began his career as a junior with Kispest AC,[10] where his \
|
||||
father, who had previously played for the club, was a coach. He had grandchildren, who were the \
|
||||
children of his brothers son[clarification needed]; the two sons of his brother are Zoltan and \
|
||||
Istvan, the first one have 3 children; Ilonka, Camila and Andres, and the second one have two.''',
|
||||
'''He changed his name to Puskas. He initially used the pseudonym "Miklos Kovacs" to help \
|
||||
circumvent the minimum age rules[12] before officially signing at the age of 12. Among his early \
|
||||
teammates was his childhood friend and future international teammate Jozsef Bozsik. He made his \
|
||||
first senior appearance for Kispest in November 1943 in a match against Nagyvaradi AC.[13] It was \
|
||||
here where he got the nickname "Ocsi" or "Buddy".[14]''',
|
||||
'''Kispest was taken over by the Hungarian Ministry of Defence in 1949, becoming the Hungarian Army \
|
||||
team and changing its name to Budapest Honved. As a result, football players were given military \
|
||||
ranks. Puskas eventually became a major (Hungarian: Ornagy), which led to the nickname "The \
|
||||
Galloping Major".[15] As the army club, Honved used conscription to acquire the best Hungarian \
|
||||
players, leading to the recruitment of Zoltan Czibor and Sandor Kocsis.[16] During his career at \
|
||||
Budapest Honved, Puskas helped the club win five Hungarian League titles. He also finished as top \
|
||||
goal scorer in the league in 1947-48, 1949-50, 1950 and 1953, scoring 50, 31, 25 and 27 goals, \
|
||||
respectively. In 1948, he was the top goal scorer in Europe.[17]''' ]
|
||||
|
||||
def main():
|
||||
print('Welcome!')
|
||||
|
||||
while True:
|
||||
print('puskas> ', end='')
|
||||
num = input()
|
||||
|
||||
if num == 'exit':
|
||||
break
|
||||
if num == 'all':
|
||||
print('\r\n'.join(puskas_wiki))
|
||||
continue
|
||||
try:
|
||||
if int(num) in range(len(puskas_wiki)):
|
||||
print(puskas_wiki[int(num)])
|
||||
continue
|
||||
except:
|
||||
pass
|
||||
print('unknown command')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
71
tests/test_long.py
Normal file
71
tests/test_long.py
Normal file
@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python
|
||||
'''
|
||||
PEXPECT LICENSE
|
||||
|
||||
This license is approved by the OSI and FSF as GPL-compatible.
|
||||
http://opensource.org/licenses/isc-license.txt
|
||||
|
||||
Copyright (c) 2012, Noah Spurrier <noah@noah.org>
|
||||
PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
|
||||
PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
|
||||
COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
'''
|
||||
import wexpect
|
||||
import unittest
|
||||
import sys
|
||||
import os
|
||||
from . import PexpectTestCase
|
||||
from . import long_printer
|
||||
|
||||
puskas_wiki = long_printer.puskas_wiki
|
||||
|
||||
class TestCaseLong(PexpectTestCase.PexpectTestCase):
|
||||
def test_long (self):
|
||||
|
||||
here = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.insert(0, here)
|
||||
|
||||
# With quotes (C:\Program Files\Python37\python.exe needs quotes)
|
||||
python_executable = '"' + sys.executable + '" '
|
||||
child_script = here + '\\long_printer.py'
|
||||
|
||||
|
||||
longPrinter = python_executable + ' ' + child_script
|
||||
prompt = 'puskas> '
|
||||
|
||||
# Start the child process
|
||||
p = wexpect.spawn(longPrinter)
|
||||
# Wait for prompt
|
||||
p.expect(prompt)
|
||||
|
||||
for i in range(10):
|
||||
p.sendline('0')
|
||||
p.expect(prompt)
|
||||
self.assertEqual(p.before.splitlines()[1], puskas_wiki[0])
|
||||
|
||||
p.sendline('all')
|
||||
p.expect(prompt)
|
||||
for a,b in zip(p.before.splitlines()[1:], puskas_wiki):
|
||||
self.assertEqual(a, b)
|
||||
|
||||
for j, paragraph in enumerate(puskas_wiki):
|
||||
p.sendline(str(j))
|
||||
p.expect(prompt)
|
||||
self.assertEqual(p.before.splitlines()[1], paragraph)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
suite = unittest.makeSuite(TestCaseLong,'test')
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user