Browse Source

added new tests for lookup and available now

pull/24/head
theycallmemac 3 years ago
parent
commit
c41dd7f42e
7 changed files with 111 additions and 12 deletions
  1. +4
    -2
      .travis.yml
  2. +2
    -2
      scripts/utils.py
  3. +42
    -0
      tests/available_now_integration.py
  4. +46
    -0
      tests/lookup_building_integration.py
  5. +2
    -3
      tests/test_available_now_output.py
  6. +3
    -5
      tests/test_lookup_output.py
  7. +12
    -0
      tests/test_required.py

+ 4
- 2
.travis.yml View File

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

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

notifications:
email: false

+ 2
- 2
scripts/utils.py View File

@@ -8,8 +8,8 @@ __license__ = 'GPL-3.0'


def get_lst(c, g, options):
if options.computing: lst = c
elif options.grattan: lst = g
if options.computing == True: lst = c
elif options.grattan == True: lst = g
return lst

def get_current_time(date):


+ 42
- 0
tests/available_now_integration.py View File

@@ -0,0 +1,42 @@
import unittest
import sys
import datetime
from scripts.utils import get_lst
from scripts.now import Now
from test_required import required
class AvailableNowIntegrationTestCase(unittest.TestCase):
def setUp(self):
return required()

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)
week, day, hour, minute = '2', '1', '14', '30'
now = Now(week, day, hour, minute)
now.check_args()
now.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)
week, day, hour, minute = '24', '2', '08', '00'
now = Now(week, day, hour, minute)
now.check_args()
now.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)
week, day, hour, minute = '60', '7', '23', '57'
now = Now(week, day, hour, minute)
try:
now.check_args()
now.check_time(info[0])
except SystemExit:
pass
if __name__ == '__main__':
unittest.main()


+ 46
- 0
tests/lookup_building_integration.py View File

@@ -0,0 +1,46 @@
import unittest
import sys
import datetime
from scripts.utils import get_lst
from scripts.lookup 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()
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)
week, day, hour = '9', '2', '0930'
look = LookUp(week, day, hour)
look.check_args()
look.check_time(info[0])


def test_incorrect_lookups(self):
parser, (options, arguments), rooms, info = required()
try:
assert not isinstance(rooms, basestring) and not isinstance(info, basestring)
except TypeError:
print("Type error has occured")
sys.exit(1)
(options, args) = parser.parse_args(["-L"])
lst = get_lst(rooms[0], rooms[1], options)
week, day, hour = '53', '7', '1600'
look = LookUp(week, day, hour)
try:
look.check_args()
look.check_time(info[0])
except SystemExit:
pass

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


tests/test_available_now.py → tests/test_available_now_output.py View File

@@ -4,15 +4,14 @@ import datetime
import os
sys.path.append('.')


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

def test_available_output(self):
if self.test_options():
if self.setUp():
with open('available_output.txt') as f:
for line in f:
if len(line.strip()[14:]) > 0:

tests/test_lookup.py → tests/test_lookup_output.py View File

@@ -4,19 +4,18 @@ import datetime
import os
sys.path.append('.')
class LookupTestCase(unittest.TestCase):
def test_options(self):
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)

def test_lookup_output(self):
if self.test_options():
if self.setUp():
with open('lookup_room_output.txt') as f:
for line in f:
if len(line.strip()[14:]) > 0:
@@ -25,14 +24,13 @@ class LookupTestCase(unittest.TestCase):
else:
self.assertEqual("", line.strip()[14:])

with open('lookup_building_output.txt') as f:
with open('lookup_building_output.txt') as f:
for line in f:
if len(line.strip()[14:]) > 0:
self.assertEqual("""Outside scheduled timetables.
Try again at 08:00.""", line.strip())
else:
self.assertEqual("", line.strip()[14:])

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


+ 12
- 0
tests/test_required.py View File

@@ -0,0 +1,12 @@
import unittest
import sys
import datetime
import os
from scripts.main import required
class RequiredTestCase(unittest.TestCase):
def test_required(self):
parser, (options, arguments), rooms, info = required()
self.assertNotIsInstance(rooms, basestring) and self.asserNotIsInstance(info, basestring)
if __name__ == '__main__':
unittest.main()


Loading…
Cancel
Save