def test_three_col_string_throws_exception(self): """Test that a three column string causes a WarnValueError Exception""" test_object = EntityListBuilder('none') with self.assertRaises(WarnValueError) as context: test_object.build_list_from_string(self.THREE_COL_STRING) self.assertTrue('Insufficient columns to create an EntityList' in context.exception.args)
def test_list_builder_limits_via_from_string_arg_no_arg(self): """Check that we get the right length list when we do not supply a limit argument to the build_list_from_string() function""" test_object = EntityListBuilder('none') entity_list = test_object.build_list_from_string( self.VALID_LONG_STRING) self.assertEqual(30, len(entity_list), "Should be 30 entries")
def test_list_builder_limits_via_from_string_arg_higher_arg(self): """Check that we a limit argument greater than the number of items in the supplied string has no effect on returned list length from the build_list_from_string() function""" test_object = EntityListBuilder('none') entity_list = test_object.build_list_from_string( self.VALID_LONG_STRING, 999) self.assertEqual(30, len(entity_list), "Should be 30 entries")
def test_builder_detects_clashes_of_list_name(self): """ Test that asking an EntityListBuilder to create two lists with the same name raises a KillValueExceptionException """ test_object = EntityListBuilder('none') try: entitylist = test_object.build_list_from_string( self.VALID_STRING_REPEATS) except WarnValueError: self.fail("Should not have got here because string is valid") self.assertTrue(len(entitylist) == 1, "Expected list to have 1 entry") self.assertFalse(entitylist.is_ranked, "Expected list NOT to be ranked") with self.assertRaises(KillValueError) as context: test_object.build_list_from_string(self.VALID_STRING_REPEATS) self.assertTrue( 'List with that name already exists' in context.exception.args)
def test_list_builder_limits_via_constructor(self, mock_logger): """Check that we can limit the size of the list returned by setting the value in the EntityListBuilder constructor""" test_object = EntityListBuilder('none', 13) entity_list = test_object.build_list_from_string( self.VALID_LONG_STRING) self.assertEqual(13, len(entity_list), "Should be 13 entries") mock_logger.assert_called_with("Some data in list 'n' was ignored due " "to a limit on list lengths (13). Up " "to 17 columns were skipped.")
def test_list_builder_limits_via_from_string_arg_lower_arg( self, mock_logger): """Check that we can limit the length of the returned list by passing in a parameter to the build_list_from_string() function""" test_object = EntityListBuilder('none') entity_list = test_object.build_list_from_string( self.VALID_LONG_STRING, 19) self.assertEqual(19, len(entity_list), "Should be 19 entries") mock_logger.assert_called_with("Some data in list 'n' was ignored due " "to a limit on list lengths (19). Up " "to 11 columns were skipped.")
def test_list_builder_fnctn_arg_overrides_constructor_limit( self, mock_logger): """Check that the value we supply as an argument to the list_builder from string function overrides the value we pass in to the constructor """ test_object = EntityListBuilder('none', 13) entity_list = test_object.build_list_from_string( self.VALID_LONG_STRING, 18) self.assertEqual(18, len(entity_list), "Should be 18 entries") mock_logger.assert_called_with("Some data in list 'n' was ignored due " "to a limit on list lengths (18). Up " "to 12 columns were skipped.")
def test_list_builder_limits_via_from_string_allows_for_gaps( self, mock_logger): """Check that we can limit the length of the returned list by passing in a parameter to the build_list_from_string() function and this works even if there are gaps in the columns supplied""" test_object = EntityListBuilder('none') entity_list = test_object.build_list_from_string( self.VALID_LONG_STRING_WITH_GAPS, 23) self.assertEqual(23, len(entity_list), "Should be 23 entries") mock_logger.assert_called_with("Some data in list 'n' was ignored due " "to a limit on list lengths (23). Up " "to 5 columns were skipped.")
def test_valid_string_builds_acceptable_list(self): """ Test that a valid string results in a list of the correct type with the expected number of entities in it """ test_object = EntityListBuilder('none') try: entitylist = test_object.build_list_from_string(self.VALID_STRING) except WarnValueError: self.fail("Should not have got here because string is valid") self.assertTrue( len(entitylist) == 3, "Expected list to have 3 entries") self.assertTrue(entitylist.is_ranked, "Expected list to be ranked")
def test_builder_strips_repeats(self): """ Test that a valid string with repeats results in the correct number of entities being included in the list """ test_object = EntityListBuilder('none') try: entitylist = test_object.build_list_from_string( self.VALID_STRING_REPEATS) except WarnValueError: self.fail("Should not have got here because string is valid") self.assertTrue(len(entitylist) == 1, "Expected list to have 1 entry") self.assertFalse(entitylist.is_ranked, "Expected list NOT to be ranked")
def test_four_col_string_does_not_throw_exception(self): """ Test that a four column string does not cause a WarnValueError Exception """ test_object = EntityListBuilder('none') try: entitylist = test_object.build_list_from_string( self.FOUR_COL_STRING) except WarnValueError: self.fail("Should not have got here because four columns is " "sufficient") self.assertTrue(len(entitylist) == 0) self.assertTrue(entitylist.is_ranked)
def test_string_with_trailing_blanks_builds_no_warn(self, mock_logger): """ Test that a string that contains blank columns results in a list of the correct type with the expected number of entities in it """ test_object = EntityListBuilder('none') # noinspection PyBroadException try: entitylist = test_object.build_list_from_string( self.VALID_STRING_TRAILING_BLANK_COLS) except WarnValueError: self.fail("Should not have got here because string is valid") except BaseException: self.fail("Should not get here either") self.assertEqual(3, len(entitylist), "Expected list to have 3 entries") self.assertTrue(entitylist.is_ranked, "Expected list to be ranked") mock_logger.assert_not_called()