def test_fetch(self): with self.assertRaises(ValueError): signac.fetch(None) with self.assertRaises(errors.FetchError): signac.fetch(dict()) self.setup_project() crawler = indexing.MasterCrawler(root=self._tmp_dir.name) crawler.tags = {'test1'} docs = list(crawler.crawl()) self.assertEqual(len(docs), 2) for doc in docs: with signac.fetch(doc) as file: pass for doc, file in indexing.fetched(docs): doc2 = json.load(file) self.assertEqual(doc['a'], doc2['a']) file.close()
def test_fetch(self): with pytest.deprecated_call(): with pytest.raises(ValueError): signac.fetch(None) with pytest.raises(errors.FetchError): signac.fetch(dict()) self.setup_project() crawler = indexing.MainCrawler(root=self._tmp_dir.name) crawler.tags = {'test1'} with pytest.deprecated_call(): docs = list(crawler.crawl()) assert len(docs) == 2 for doc in docs: with pytest.deprecated_call(): with signac.fetch(doc) as file: pass with pytest.deprecated_call(): for doc, file in indexing.fetched(docs): doc2 = json.load(file) assert doc['a'] == doc2['a'] file.close()
def test_master_crawler(self): self.setup_project() crawler = indexing.MasterCrawler(root=self._tmp_dir.name) crawler.tags = {'test1'} no_find = True for doc in crawler.crawl(): no_find = False ffn = os.path.join(doc['root'], doc['filename']) self.assertTrue(os.path.isfile(ffn)) with open(ffn) as file: doc2 = json.load(file) self.assertEqual(doc2['a'], doc['a']) with signac.fetch(doc) as file: pass self.assertFalse(no_find)
def test_main_crawler(self): self.setup_project() crawler = indexing.MainCrawler(root=self._tmp_dir.name) crawler.tags = {'test1'} no_find = True with pytest.deprecated_call(): for doc in crawler.crawl(): no_find = False ffn = os.path.join(doc['root'], doc['filename']) assert os.path.isfile(ffn) with open(ffn) as file: doc2 = json.load(file) assert doc2['a'] == doc['a'] with signac.fetch(doc) as file: pass assert not no_find
def test_index(self): self.setup_project() root = self._tmp_dir.name self.assertEqual(len(list(signac.index(root=root))), 0) index = signac.index(root=self._tmp_dir.name, tags={'test1'}) no_find = True for doc in index: no_find = False ffn = os.path.join(doc['root'], doc['filename']) self.assertTrue(os.path.isfile(ffn)) with open(ffn) as file: doc2 = json.load(file) self.assertEqual(doc2['a'], doc['a']) with signac.fetch(doc) as file: pass self.assertFalse(no_find)
def test_index(self): self.setup_project() root = self._tmp_dir.name with pytest.deprecated_call(): assert len(list(signac.index(root=root))) == 0 index = signac.index(root=self._tmp_dir.name, tags={'test1'}) no_find = True for doc in index: no_find = False ffn = os.path.join(doc['root'], doc['filename']) assert os.path.isfile(ffn) with open(ffn) as file: doc2 = json.load(file) assert doc2['a'] == doc['a'] with pytest.deprecated_call(): with signac.fetch(doc) as file: pass assert not no_find