'Verify that raw values are preferred for grouping,
including fallbacks for missing raw data or invalid type'

def testRawValuePrecedence(self):

    assertEqual = self.assertEqual
    items = [{'name': 'Item1', 'type': 'A', '_row': {'name': 'Item1', 'type': 'X'}}, {'name': 'Item2', 'type': 'C', '_row': {'name': 'Item2', 'type': 'Y'}}, {'name': 'Item3', 'type': 'D', '_row': {'name': 'Item3', 'type': 'Z'}}, {'name': 'Item4', 'type': 'B', '_row': 'test'}, {'name': 'Item5', 'type': 'A', '_row': {'name': 'Item5', 'type': 'X'}}, {'name': 'Item6', 'type': 'D', '_row': {'name': 'Item6', 'type': 'Z'}}, {'name': 'Item7', 'type': 'E'}]
    types = ['X', 'Y', 'Z', 'B', 'E']
    gi = S3GroupedItems(items, groupby=['type'])
    for (index, group) in enumerate(gi.groups):
        assertEqual(group['type'], types[index])
