

def setUp(self):
    self.db = mongomock.MongoClient().map_reduce_test
    self.data = [{
        'x': 1,
        'tags': ['dog', 'cat'],
    }, {
        'x': 2,
        'tags': ['cat'],
    }, {
        'x': 3,
        'tags': ['mouse', 'cat', 'dog'],
    }, {
        'x': 4,
        'tags': [],
    }]
    for item in self.data:
        self.db.things.insert(item)
    self.map_func = Code('\n                function() {\n                    this.tags.forEach(function(z) {\n                        emit(z, 1);\n                    });\n                }')
    self.reduce_func = Code('\n                function(key, values) {\n                    var total = 0;\n                    for(var i = 0; i<values.length; i++) {\n                        total += values[i];\n                    }\n                    return total;\n                }')
    self.expected_results = [{
        '_id': 'mouse',
        'value': 1,
    }, {
        '_id': 'dog',
        'value': 2,
    }, {
        '_id': 'cat',
        'value': 3,
    }]

dataset/ETHPy150Open vmalloc/mongomock/tests/test__mongomock.py CollectionMapReduceTest.setUp/original