Beispiel #1
0
 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)
Beispiel #2
0
 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
Beispiel #3
0
 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)
Beispiel #4
0
 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
Beispiel #5
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()

        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
Beispiel #6
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)
Beispiel #7
0
 def setUp(self):
     self.c = Collection()
Beispiel #8
0
 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)
Beispiel #9
0
 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
Beispiel #10
0
 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
Beispiel #11
0
 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
Beispiel #12
0
 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
Beispiel #13
0
 def __init__(self) :
    from signac import Collection
    self.info = {}
    self.coll = Collection()
Beispiel #14
0
 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)
Beispiel #15
0
 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)
Beispiel #16
0
 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)
Beispiel #17
0
 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)
Beispiel #18
0
 def get_index_collection(self):
     c = Collection()
     return Mock(spec=c, wraps=c)
Beispiel #19
0
 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