class TestAllocationFromFile(unittest.TestCase): def setUp(self): """ Creates the context on which tests will be run. """ # Create users for the test and write them to file users = ">Anthony Nandaa\n#Eric Gichuri\n#Mahad Walusimbi\n>Godson Ukpere\n##Kevin Ndungu\n>Joshua Mwaniki\n" alloFile = open('data/input.txt', 'w+') alloFile.write(users) alloFile.close() # Create rooms for the test and write them to file spaces = "+Heroku\n\tThomas Nyambati\n\tJeremy Kithome\n\tCollin Mutembei\n\tBrian Koech\n+Sound Cloud\n+Node\n+Digital Ocean\n\tGertrude Nyenyeshi\n\tStacey A.\n-Staff Room\n-Office 1\n-Office 2\n-Office 3\n-Office 4\n-Office 5\n" roomsFile = open('data/allocated.txt', 'w+') roomsFile.write(spaces) roomsFile.close() # Initialize amity campus self.campus = Amity() self.campus.prePopulate() def tearDown(self): """ Performs housekeeping to clean up test files after tests have been executed. """ os.remove('data/input.txt') os.remove('data/allocated.txt') def test_prepopulate(self): """ Expects 4 living spaces and 6 office rooms. """ self.assertEqual(len(self.campus.livingRooms), 4) self.assertEqual(len(self.campus.officeRooms), 6) def test_unallocated_people(self): """ Expect unallocateed people to be 6. """ uFile = open('data/input.txt') unallocated = [] for line in uFile.readlines(): unallocated.append(line) self.assertEqual(len(unallocated), 6) def test_fellows_allocated_living(self): """ Expect fellows allocated living spaces to be 6. """ aFile = open('data/allocated.txt') allocated = [] for line in aFile.readlines(): if (line[0] == '\t'): allocated.append(line) self.assertEqual(len(allocated), 6) def test_allocate_through_app(self): """ Expects exception when allocation is performed on a full room. """ # Expect the first room (Heroku) to have 4 occupants heroku = self.campus.livingRooms[0] self.assertEqual(len(heroku.occupants), 4) # Expect the fourth room (Digital Ocean) to have 2 occupants docean = self.campus.livingRooms[3] self.assertEqual(len(docean.occupants), 2) # Expect OverflowException because heroku is full aFellow = Fellow("Martin Nate") with self.assertRaises(OverflowException): heroku.addFellow(aFellow) # Expect TypeError when staff added to living space staffer = Staff("Hellen Maina") with self.assertRaises(TypeError): heroku.addFellow(staffer)
from random import random from spaces.living import Living from spaces.office import Office from custom import utilities from amity import Amity from people.fellow import Fellow from people.staff import Staff campus = Amity() campus.prePopulate() # useful vars rangeError = 'Range error: *** Please select a number that is within the range' valueError = 'Value error: *** Please enter a number in digit form ***\n' file_path = utilities.getPath('data/') while (True): utilities.mainMenu() answer = raw_input('Enter a number between 0 - 5 to select a menu.\n') try: # catch non integer input from the user answer = int(answer) # catch int that are outside the range in the menu if ((answer < 0) or (answer > 5)): utilities.clearScreen() print rangeError, ' 0 - 5 ***\n' continue except ValueError: utilities.clearScreen()