class TestAmity(unittest.TestCase):

    def setUp(self):
        self.amity = Amity()
        self.amity.prepopulate()
        self.parser = self.amity.create_parser()
        args = self.parser.parse_args(["input.txt"])
        self.amity.inputfile = args.inputfile
        self.amity.inputfile_reader()
        self.amity.allocate()

    def tearDown(self):
        del self.amity.rooms['office']
        del self.amity.rooms['living']
        self.amity.people = []

    def test_script_with_empty_args(self):
        with self.assertRaises(SystemExit):
            self.parser.parse_args([])

    def test_initial_rooms_in_amity(self):
        self.assertEqual(len(self.amity.rooms[
                         'living']), 10, msg="Amity should be preloaded with 10 living spaces")
        self.assertEqual(len(
            self.amity.rooms['office']), 10, msg="Amity should be preloaded with 10 offices")

    def test_number_of_persons_from_input(self):
        self.assertEquals(len(self.amity.people), 64)

    def test_members_of_room(self):
        self.assertLessEqual(
            len(self.amity.rooms['office'][0].get_members()), 6)
        self.assertLessEqual(
            len(self.amity.rooms['living'][0].get_members()), 4)

    def test_current_size_of_room(self):
        self.assertLessEqual(self.amity.rooms['office'][0].current_size(), 6)
        self.assertLessEqual(self.amity.rooms['living'][9].current_size(), 4)

    def test_unallocated(self):
        self.assertGreaterEqual(len(self.amity.unallocated['living']), 0)
        self.assertGreaterEqual(len(self.amity.unallocated['office']), 0)

    def test_total_number_of_romms_in_Amity(self):
        self.assertEquals(len(self.amity.get_rooms()), 20)

    @patch('sys.stdout', new_callable=StringIO)
    def test_print_result(self, mock_out):
        result_str = "Result:"
        self.amity.print_result()
        self.assertIn(result_str, mock_out.getvalue())

    @patch('sys.stdout', new_callable=StringIO)
    def test_print_unallocated(self, mock_out):
        result_str = "After Allocation, the following could not be allocated"
        self.amity.print_unallocated()
        self.assertIn(result_str, mock_out.getvalue())
                                    continue
                            except ValueError:
                                utilities.clearScreen()
                                print valueError
                            else:
                                if (how == 0):
                                    utilities.clearScreen()
                                    # Quit this menu
                                    break
                                elif (how == 1):
                                    utilities.clearScreen()
                                    while (True):
                                        staffName = raw_input('Enter the name of the staff member. \n')
                                        if staffName:
                                            worker = Staff(staffName)
                                            campus.allocate(worker, 'Office')
                                            break
                                elif (how == 2):
                                    utilities.clearScreen()

                                    # read from unallocated list file
                                    uStaff = open(file_path + 'input.txt')
                                    uStaffList = []
                                    edits = ''
                                    for line in uStaff.readlines():
                                        if line[0] == '>':
                                            staff = Staff(line[1::])
                                            uStaffList.append(staff)
                                        elif line[0] != '>':
                                            edits += line