def test_eq(self): key1 = MongoKey({'doc': 1, 'id': 2}) key2 = MongoKey({'doc': 1, 'id': 2}) assert key1 == key2 key3 = MongoKey({'doc': 1, 'id': 3}) assert key1 != key3 key4 = MongoKey({'doc': 1, 'id': 2}, field_name='xxx') assert key1 != key4 assert key2 != key4
def test_mongo_key(self): backend = self.init_backend() key = MongoKey({'experiment_id': 'test_mongo_key', 'trial_id': 1}) backend.set(key, 100) assert backend.get(key) == 100 backend.set(key, 200) assert backend.get(key) == 200 new_key = MongoKey({'experiment_id': 'test_mongo_key', 'trial_id': 2}) backend.set(new_key, 300) assert backend.get(new_key) == 300 assert backend.get(key) == 200
def test_mongo_key_internal(self): backend = self.init_backend() key = MongoKey({ 'experiment_id': 'test_mongo_key_internal', 'trial_id': 1354, 'internal_unique_key': 'xxxxx' }) backend.set(key, 100) assert backend.get(key) == 100 key = MongoKey({'internal_unique_key': 'xxxxx'}, field_name='experiment_id') assert backend.get(key) == 'test_mongo_key_internal' key = MongoKey({'internal_unique_key': 'xxxxx'}, field_name='trial_id') assert backend.get(key) == 1354
def test_increment_mongo_key(self): backend = self.init_backend() key = MongoKey({ 'experiment_id': 'test_increment_mongo_key', 'trial_id': 1 }) assert backend.increment(key) == 1 assert backend.increment(key) == 2 assert backend.increment(key) == 3 assert backend.increment(key) == 4 new_key = MongoKey({ 'experiment_id': 'test_increment_mongo_key', 'trial_id': 2 }) assert backend.increment(new_key) == 1 assert backend.increment(key) == 5
def test_append_list_mongo_key(self): backend = self.init_backend() key = MongoKey({ 'experiment_id': 'test_append_list_mongo_key', 'trial_id': 1 }) backend.append_list(key, 10) assert backend.get_list(key) == [10] backend.append_list(key, 20) assert backend.get_list(key) == [10, 20]
def test_wildcard(self): key = MongoKey({'key1': 1, 'key2': 2, 'key3': '*'}) assert key.document_meta == {'key1': 1, 'key2': 2}
def test_repr(self): key = MongoKey({'doc': 1, 'id': 2}) exp = "MongoKey(meta={'doc': 1, 'id': 2}, field_name=value)" assert repr(key) == exp
def make_key(self, key): return MongoKey({'test_mongo_key': key})