Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.41 KB | None | 0 0
  1. import pytest, os, pickle
  2. import TC2 as student
  3.  
  4. def test_next_block1():
  5.     f = open('test.txt','w')
  6.     rep = "category\nquestion\na1\na2\na3\na4\n1\nexplanation\n1\n"
  7.     f.write(rep)
  8.     f.close()
  9.     f = open('test.txt','r')
  10.     assert student.next_block(f) == ("category\n","question\n",["a1\n","a2\n","a3\n","a4\n"],"1","explanation\n",1)
  11.     f.close()
  12.     os.remove('test.txt')
  13. def test_next_block2():
  14.     f = open('test.txt','w')
  15.     rep = "category\nquestion\na1\na2\na3\na4\n1\nexplanation\n14\n"
  16.     f.write(rep)
  17.     f.close()
  18.     f = open('test.txt','r')
  19.     assert student.next_block(f) == ("category\n","question\n",["a1\n","a2\n","a3\n","a4\n"],"1","explanation\n",14)
  20.     f.close()
  21.     os.remove('test.txt')
  22. def test_next_block3():
  23.     f = open('test.txt','w')
  24.     rep = "category\nquestion\na1\na2\na3\na4\n1\nexplanation\n140\n"
  25.     f.write(rep)
  26.     f.close()
  27.     f = open('test.txt','r')
  28.     assert student.next_block(f) == ("category\n","question\n",["a1\n","a2\n","a3\n","a4\n"],"1","explanation\n",140)
  29.     f.close()
  30.     os.remove('test.txt')
  31.  
  32. def test_sortNsave1():
  33.     hs = [(2,'DEF'),(1,'GHI'),(0,'ABC')]
  34.     hs = student.sortNsave(3,'ABC',hs)
  35.     f = open('highscores.dat',"rb")
  36.     hs1 = pickle.load(f)
  37.     f.close()
  38.     assert hs1 == hs and hs == [(3,'ABC'),(2,'DEF'),(1,'GHI')]
  39. def test_sortNsave2():
  40.     hs = [(20,'DEF'),(10,'GHI'),(15,'ABC')]
  41.     hs = student.sortNsave(3,'NEW',hs)
  42.     f = open('highscores.dat',"rb")
  43.     hs1 = pickle.load(f)
  44.     f.close()
  45.     assert hs1 == hs and hs == [(20,'DEF'),(15,'ABC'),(10,'GHI')]
  46. def test_sortNsave3():
  47.     hs = [(20,'DEF'),(10,'GHI'),(15,'ABC')]
  48.     hs = student.sortNsave(30,'NEW',hs)
  49.     f = open('highscores.dat',"rb")
  50.     hs1 = pickle.load(f)
  51.     f.close()
  52.     assert hs1 == hs and hs == [(30,'NEW'),(20,'DEF'),(15,'ABC')]
  53.  
  54. def test_hs_table1():
  55.     hs = [(20,'DEF'),(10,'GHI'),(15,'ABC')]
  56.     assert student.hs_table(hs) == 'Name: DEF\tScore: 20\nName: GHI\tScore: 10\nName: ABC\tScore: 15\n'
  57. def test_hs_table2():
  58.     hs = [(2,'DEF'),(1,'GHI'),(0,'ABC')]
  59.     assert student.hs_table(hs) == 'Name: DEF\tScore: 2\nName: GHI\tScore: 1\nName: ABC\tScore: 0\n'
  60. def test_hs_table3():
  61.     hs = [(2,'DEF'),(1,'GHI'),(0,'ABC'),(20,'DEF'),(10,'GHI'),(15,'ABC')]
  62.     assert student.hs_table(hs) == 'Name: DEF\tScore: 2\nName: GHI\tScore: 1\nName: ABC\tScore: 0\nName: DEF\tScore: 20\nName: GHI\tScore: 10\nName: ABC\tScore: 15\n'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement