def test_copy(self): docs = [dict(_id=str(i)) for i in range(10)] self.c.update(docs) c2 = Collection(self.c) self.assertEqual(len(self.c), len(c2)) for doc in c2: self.assertEqual(len(self.c.find(doc)), 1)
def test_copy(self): docs = [dict(_id=str(i)) for i in range(10)] self.c.update(docs) c2 = Collection(self.c) assert len(self.c) == len(c2) for doc in c2: assert len(self.c.find(doc)) == 1
def test_init_with_list_with_and_without_ids(self): docs = [{'a': i} for i in range(10)] for i, doc in enumerate(islice(docs, 5)): doc.setdefault('_id', str(i)) self.c = Collection(docs) self.assertEqual(len(self.c), len(docs)) for doc in docs: self.assertIn(doc['_id'], self.c)
def test_init_with_list_with_and_without_ids(self): docs = [{"a": i} for i in range(10)] for i, doc in enumerate(islice(docs, 5)): doc.setdefault("_id", str(i)) self.c = Collection(docs) assert len(self.c) == len(docs) for doc in docs: assert doc["_id"] in self.c
def test_compression(self): # Fill with data docs = [dict(_id=str(i)) for i in range(10)] self.c.update(docs) self.c.flush() # Create uncompressed copy to compare to. c2 = Collection(self.c) c2.flush() assert isinstance(self.c._file, io.BytesIO) size_compressed = len(self.c._file.getvalue()) assert size_compressed > 0 size_uncompressed = len(c2._file.getvalue().encode("utf-8")) assert size_uncompressed > 0 compresslevel = size_uncompressed / size_compressed assert compresslevel > 1.0
def test_compression(self): # Fill with data docs = [dict(_id=str(i)) for i in range(10)] self.c.update(docs) self.c.flush() # Create uncompressed copy to compare to. c2 = Collection(self.c) c2.flush() self.assertIsInstance(self.c._file, io.BytesIO) size_compressed = len(self.c._file.getvalue()) self.assertGreater(size_compressed, 0) size_uncompressed = len(c2._file.getvalue().encode('utf-8')) self.assertGreater(size_uncompressed, 0) compresslevel = size_uncompressed / size_compressed self.assertGreater(compresslevel, 1.0)
def setUp(self): self.c = Collection()
def test_init_with_non_serializable(self): docs = [dict(a=array.array("f", [1, 2, 3])) for i in range(10)] with pytest.raises(TypeError): self.c = Collection(docs)
def test_init_with_list_without_ids(self): docs = [{"a": i} for i in range(10)] self.c = Collection(docs) assert len(self.c) == len(docs) for doc in docs: assert doc["_id"] in self.c
def test_init_with_list_with_ids_non_sequential(self): docs = [{"a": i, "_id": "{:032d}".format(i**3)} for i in range(10)] self.c = Collection(docs) assert len(self.c) == len(docs) for doc in docs: assert doc["_id"] in self.c
def test_init_with_list_with_ids_sequential(self): docs = [{"a": i, "_id": str(i)} for i in range(10)] self.c = Collection(docs) assert len(self.c) == len(docs) for doc in docs: assert doc["_id"] in self.c
def test_buffer_size(self): docs = [{"a": i, "_id": str(i)} for i in range(10)] self.c = Collection(docs) assert len(self.c._file.getvalue()) == 0 self.c.flush() assert len(self.c._file.getvalue()) > 0
def __init__(self) : from signac import Collection self.info = {} self.coll = Collection()
def test_init_with_list_without_ids(self): docs = [{'a': i} for i in range(10)] self.c = Collection(docs) self.assertEqual(len(self.c), len(docs)) for doc in docs: self.assertIn(doc['_id'], self.c)
def test_init_with_list_with_ids_non_sequential(self): docs = [{'a': i, '_id': '{:032d}'.format(i**3)} for i in range(10)] self.c = Collection(docs) self.assertEqual(len(self.c), len(docs)) for doc in docs: self.assertIn(doc['_id'], self.c)
def test_init_with_list_with_ids_sequential(self): docs = [{'a': i, '_id': str(i)} for i in range(10)] self.c = Collection(docs) self.assertEqual(len(self.c), len(docs)) for doc in docs: self.assertIn(doc['_id'], self.c)
def test_buffer_size(self): docs = [{'a': i, '_id': str(i)} for i in range(10)] self.c = Collection(docs) self.assertEqual(len(self.c._file.getvalue()), 0) self.c.flush() self.assertGreater(len(self.c._file.getvalue()), 0)
def get_index_collection(self): c = Collection() return Mock(spec=c, wraps=c)
def test_init_with_list_with_ids_non_sequential(self): docs = [{'a': i, '_id': '{:032d}'.format(i**3)} for i in range(10)] self.c = Collection(docs) assert len(self.c) == len(docs) for doc in docs: assert doc['_id'] in self.c