瀏覽代碼

added more test coverage

pull/24/head
theycallmemac 3 年之前
父節點
當前提交
f9b2943401
共有 6 個檔案被更改,包括 47 行新增40 行删除
  1. +2
    -0
      .travis.yml
  2. +3
    -4
      scripts/opts.py
  3. +14
    -13
      tests/available_now_integration.py
  4. +12
    -13
      tests/lookup_building_integration.py
  5. +6
    -2
      tests/test_available_now_output.py
  6. +10
    -8
      tests/test_lookup_output.py

+ 2
- 0
.travis.yml 查看文件

@@ -8,6 +8,8 @@ install:
- pip install -r requirements.txt

script:
- python tests/available_now_integration.py
- python tests/lookup_building_integration.py
- python tests/test_lookup_output.py
- python tests/test_available_now_output.py



+ 3
- 4
scripts/opts.py 查看文件

@@ -5,7 +5,6 @@ from room_booking import RoomBooking
from lookup import LookUp
from now import Now
import utils
import shared

__author__ = "theycallmemac"
__version__ = '2.0.0'
@@ -23,7 +22,7 @@ def booking_lab(info):
lab = LabBooking(email, password, your_name, society, info[1])
emails, message = lab.draft()
print(message)
conf = shared.confirm()
conf = utils.confirm()
if conf == "y":
result = lab.send(emails[0], emails[1], message)
print(result)
@@ -34,7 +33,7 @@ def booking_room(info):
email, number, name, society = get_room_credentials()
room = RoomBooking(email, number, name, society, info[1])
form = room.fill()
conf = shared.confirm()
conf = utils.confirm()
if conf == "y":
result = room.submit(form)
print(result)
@@ -45,7 +44,7 @@ def lookup_building(rooms, info, options):
lst = utils.get_lst(rooms[0], rooms[1], options)
week, day, hour = info[1]
look = LookUp(week, day, hour)
shared.check_args(week, day)
utils.check_args(week, day)
look.check_time(info[0])
look.building_option(lst)



+ 14
- 13
tests/available_now_integration.py 查看文件

@@ -1,9 +1,10 @@
import unittest
import sys
import datetime
from scripts.utils import get_lst
from scripts.now import Now
from scripts import utils
from scripts import now
from test_required import required

class AvailableNowIntegrationTestCase(unittest.TestCase):
def setUp(self):
return required()
@@ -11,29 +12,29 @@ class AvailableNowIntegrationTestCase(unittest.TestCase):
def test_lab(self):
parser, (options, arguments), rooms, info = self.setUp()
(options, args) = parser.parse_args(["-L"])
lst = get_lst(rooms[0], rooms[1], options)
lst = utils.get_lst(rooms[0], rooms[1], options)
week, day, hour, minute = '2', '1', '14', '30'
now = Now(week, day, hour, minute)
now.check_args()
now.check_time(info[0])
now_obj = now.Now(week, day, hour, minute)
utils.check_args(week, day)
now_obj.check_time(info[0])

def test_room(self):
parser, (options, arguments), rooms, info = self.setUp()
(options, args) = parser.parse_args(["-C"])
lst = get_lst(rooms[0], rooms[1], options)
lst = utils.get_lst(rooms[0], rooms[1], options)
week, day, hour, minute = '24', '2', '08', '00'
now = Now(week, day, hour, minute)
now.check_args()
now.check_time(info[0])
now_obj = now.Now(week, day, hour, minute)
utils.check_args(week, day)
now_obj.check_time(info[0])

def test_incorrect_input(self):
parser, (options, arguments), rooms, info = self.setUp()
(options, args) = parser.parse_args(["-L"])
lst = get_lst(rooms[0], rooms[1], options)
lst = utils.get_lst(rooms[0], rooms[1], options)
week, day, hour, minute = '60', '7', '23', '57'
now = Now(week, day, hour, minute)
now_obj = now.Now(week, day, hour, minute)
try:
now.check_args()
utils.check_args(week, day)
except SystemExit:
pass
if __name__ == '__main__':


+ 12
- 13
tests/lookup_building_integration.py 查看文件

@@ -1,29 +1,28 @@
import unittest
import sys
import datetime
from scripts.utils import get_lst
from scripts.lookup import LookUp
from scripts import utils
from scripts import lookup
from test_required import required
class LookupBuildingIntegrationTestCase(unittest.TestCase):
def test_lab_lookups(self):
parser, (options, arguments), rooms, info = required()
(options, args) = parser.parse_args(["-L"])
lst = get_lst(rooms[0], rooms[1], options)
week, day, hour = '4', '5', '1600'
look = LookUp(week, day, hour)
look.check_args()
lst = utils.get_lst(rooms[0], rooms[1], options)
week, day, hour = '9', '5', '1600'
look = lookup.LookUp(week, day, hour)
utils.check_args(week, day)
look.check_time(info[0])

def test_room_lookups(self):
parser, (options, arguments), rooms, info = required()
(options, args) = parser.parse_args(["-C"])
lst = get_lst(rooms[0], rooms[1], options)
lst = utils.get_lst(rooms[0], rooms[1], options)
week, day, hour = '9', '2', '0930'
look = LookUp(week, day, hour)
look.check_args()
look = lookup.LookUp(week, day, hour)
utils.check_args(week, day)
look.check_time(info[0])


def test_incorrect_lookups(self):
parser, (options, arguments), rooms, info = required()
try:
@@ -32,11 +31,11 @@ class LookupBuildingIntegrationTestCase(unittest.TestCase):
print("Type error has occured")
sys.exit(1)
(options, args) = parser.parse_args(["-L"])
lst = get_lst(rooms[0], rooms[1], options)
lst = utils.get_lst(rooms[0], rooms[1], options)
week, day, hour = '53', '7', '1600'
look = LookUp(week, day, hour)
look = lookup.LookUp(week, day, hour)
try:
look.check_args()
utils.check_args(week, day)
except SystemExit:
pass



+ 6
- 2
tests/test_available_now_output.py 查看文件

@@ -6,8 +6,7 @@ sys.path.append('.')

class AvailableNowTestCase(unittest.TestCase):
def setUp(self):
available_result = os.system("""cd scripts/ && python dcurooms -anC
> ../tests/available_output.txt""")
available_result = os.system("""python scripts/dcurooms -anC > tests/available_output.txt""")
self.assertTrue(available_result == 0)

def test_available_output(self):
@@ -19,6 +18,11 @@ class AvailableNowTestCase(unittest.TestCase):
Try again at 08:00.""", line.strip())
else:
self.assertEqual("", line.strip()[14:])
self.tearDown()

def tearDown(self):
del_result = os.system("""rm tests/*.txt""")
self.assertTrue(del_result == 0)


if __name__ == '__main__':


+ 10
- 8
tests/test_lookup_output.py 查看文件

@@ -5,14 +5,9 @@ import os
sys.path.append('.')
class LookupTestCase(unittest.TestCase):
def setUp(self):
room_result = os.system("""cd scripts &&
python dcurooms -l CG12 21 1 1800
> ../tests/lookup_room_output.txt""")
building_result = os.system("""cd scripts &&
python dcurooms -lL 9 4 1500
> ../tests/lookup_building_output.txt""")
self.assertTrue(room_result == 0)
self.assertTrue(building_result == 0)
room_result = os.system("""python scripts/dcurooms -l CG12 21 1 1800 > tests/lookup_room_output.txt""")
building_result = os.system("""python scripts/dcurooms -lL 9 4 1500 > tests/lookup_building_output.txt""")
self.assertTrue(room_result == 0 and building_result == 0)

def test_lookup_output(self):
if self.setUp():
@@ -23,6 +18,7 @@ class LookupTestCase(unittest.TestCase):
Try again at 08:00.""", line.strip())
else:
self.assertEqual("", line.strip()[14:])
self.tearDown()

with open('lookup_building_output.txt') as f:
for line in f:
@@ -31,6 +27,12 @@ class LookupTestCase(unittest.TestCase):
Try again at 08:00.""", line.strip())
else:
self.assertEqual("", line.strip()[14:])
self.tearDown()

def tearDown(self):
del_result = os.system("""rm tests/*.txt""")
self.assertTrue(del_result == 0)

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


Loading…
取消
儲存