def test_get_real_allergens(self):

        # test single abstract
        allergens = ['nut']
        expected = set(['peanut', 'hazelnut', 'cashew nut', 'brazil nut', 
                    'almond', 'walnut', 'pecan', 'pistachio']) 
        actual = allergies.get_real_allergens(allergens)
        self.assertEqual(expected, actual)

        # test single abstract with capitalisation and spacing
        allergens = ['nuT  ']
        expected = set(['peanut', 'hazelnut', 'cashew nut', 'brazil nut', 
                    'almond', 'walnut', 'pecan', 'pistachio']) 
        actual = allergies.get_real_allergens(allergens)
        self.assertEqual(expected, actual)

        # test single abstract, replicated with capitalisation and spacing
        allergens = ['nuT  ', 'nut']
        expected = set(['peanut', 'hazelnut', 'cashew nut', 'brazil nut', 
                    'almond', 'walnut', 'pecan', 'pistachio']) 
        actual = allergies.get_real_allergens(allergens)
        self.assertEqual(expected, actual)

        # test multi abstract
        allergens = ['nut', 'wheat']
        expected = set(['peanut', 'hazelnut', 'cashew nut', 'brazil nut', 
                    'almond', 'walnut', 'pecan', 'pistachio', 'bread', 
                    'flour', 'pasta'])
        actual = allergies.get_real_allergens(allergens)
        self.assertEqual(expected, actual)

        # text mixing abstract and concrete
        allergens = ['nut', 'spanner']
        expected = set(['peanut', 'hazelnut', 'cashew nut', 'brazil nut', 
                    'almond', 'walnut', 'pecan', 'pistachio', 'spanner']) 
        actual = allergies.get_real_allergens(allergens)
        self.assertEqual(expected, actual)

        # text mixing abstract and concrete with dupes and mixed case
        allergens = ['nut', 'spanner', 'SpAnnER   ']
        expected = set(['peanut', 'hazelnut', 'cashew nut', 'brazil nut', 
                    'almond', 'walnut', 'pecan', 'pistachio', 'spanner']) 
        actual = allergies.get_real_allergens(allergens)
        self.assertEqual(expected, actual)

        # test just concrete (should not be modified at all)
        allergens = ['turnip']
        expected = set(['turnip'])
        actual = allergies.get_real_allergens(allergens)
        self.assertEqual(expected, actual)
Example #2
0
    def __init__(self, allergens, terms):
        self.abstract_allergens = allergens
        self.terms = terms
        self.allergens = allergies.get_real_allergens(allergens)

        self._validate_search()