コード例 #1
0
ファイル: test_indexing.py プロジェクト: csadorf/signac
 def test_export(self):
     self.setup_project()
     crawler = indexing.MasterCrawler(root=self._tmp_dir.name)
     crawler.tags = {'test1'}
     index = self.get_index_collection()
     signac.export(crawler.crawl(), index)
     self.assertTrue(index.replace_one.called or index.bulk_write.called)
     for doc in crawler.crawl():
         self.assertIsNotNone(index.find_one({'_id': doc['_id']}))
コード例 #2
0
 def test_export(self):
     self.setup_project()
     crawler = indexing.MainCrawler(root=self._tmp_dir.name)
     crawler.tags = {'test1'}
     index = self.get_index_collection()
     with pytest.deprecated_call():
         signac.export(crawler.crawl(), index)
         assert index.replace_one.called or index.bulk_write.called
         for doc in crawler.crawl():
             assert index.find_one({'_id': doc['_id']}) is not None
コード例 #3
0
ファイル: test_indexing.py プロジェクト: csadorf/signac
 def test_export_with_update(self):
     self.setup_project()
     index = list(signac.index(root=self._tmp_dir.name, tags={'test1'}))
     collection = self.get_index_collection()
     signac.export(index, collection, update=True)
     self.assertTrue(collection.replace_one.called
                     or collection.bulk_write.called)
     for doc in index:
         self.assertIsNotNone(collection.find_one({'_id': doc['_id']}))
     collection.reset_mock()
     self.assertEqual(len(index), collection.find().count())
     self.assertTrue(collection.find.called)
     signac.export(index, collection, update=True)
     self.assertTrue(collection.replace_one.called
                     or collection.bulk_write.called)
     for doc in index:
         self.assertIsNotNone(collection.find_one({'_id': doc['_id']}))
     self.assertEqual(len(index), collection.find().count())
     collection.reset_mock()
     for fn in ('a_0.txt', 'a_1.txt'):
         os.remove(os.path.join(self._tmp_dir.name, fn))
         N = len(index)
         index = list(signac.index(root=self._tmp_dir.name, tags={'test1'}))
         self.assertEqual(len(index), N - 1)
         collection.reset_mock()
         if index:
             signac.export(index, collection, update=True)
             self.assertTrue(collection.replace_one.called
                             or collection.bulk_write.called)
             self.assertEqual(len(index), collection.find().count())
         else:
             with self.assertRaises(errors.ExportError):
                 signac.export(index, collection, update=True)
コード例 #4
0
 def test_export_with_update(self):
     self.setup_project()
     with pytest.deprecated_call():
         index = list(signac.index(root=self._tmp_dir.name, tags={'test1'}))
     collection = self.get_index_collection()
     with pytest.deprecated_call():
         signac.export(index, collection, update=True)
     assert collection.replace_one.called or collection.bulk_write.called
     for doc in index:
         assert collection.find_one({'_id': doc['_id']}) is not None
     collection.reset_mock()
     assert len(index) == collection.find().count()
     assert collection.find.called
     with pytest.deprecated_call():
         signac.export(index, collection, update=True)
     assert collection.replace_one.called or collection.bulk_write.called
     for doc in index:
         assert collection.find_one({'_id': doc['_id']}) is not None
     assert len(index) == collection.find().count()
     collection.reset_mock()
     for fn in ('a_0.txt', 'a_1.txt'):
         os.remove(os.path.join(self._tmp_dir.name, fn))
         N = len(index)
         with pytest.deprecated_call():
             index = list(
                 signac.index(root=self._tmp_dir.name, tags={'test1'}))
         assert len(index) == (N - 1)
         collection.reset_mock()
         if index:
             with pytest.deprecated_call():
                 signac.export(index, collection, update=True)
             assert collection.replace_one.called or collection.bulk_write.called
             assert len(index) == collection.find().count()
         else:
             with pytest.raises(errors.ExportError):
                 with pytest.deprecated_call():
                     signac.export(index, collection, update=True)