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)
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
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)
def test_index(self): self.call('python -m signac init my_project'.split()) self.call('python -m signac project --access'.split()) project = signac.Project() project.open_job({'a': 0}).init() self.assertEqual(len(project), 1) self.assertEqual(len(list(project.index())), 1) self.assertEqual(len(list(signac.index())), 1) doc = json.loads(self.call('python -m signac index'.split())) self.assertIn('statepoint', doc) self.assertEqual(doc['statepoint'], {'a': 0}) project.open_job({'a': 0}).document['b'] = 0 doc = json.loads(self.call('python -m signac index'.split())) self.assertIn('statepoint', doc) self.assertEqual(doc['statepoint'], {'a': 0}) self.assertIn('b', doc) self.assertEqual(doc['b'], 0)
def test_index(self): self.call('python -m signac init my_project'.split()) self.call('python -m signac project --access'.split()) project = signac.Project() project.open_job({'a': 0}).init() assert len(project) == 1 with pytest.deprecated_call(): assert len(list(project.index())) == 1 assert len(list(signac.index())) == 1 doc = json.loads(self.call('python -m signac index'.split())) assert 'statepoint' in doc assert doc['statepoint'] == {'a': 0} project.open_job({'a': 0}).document['b'] = 0 doc = json.loads(self.call('python -m signac index'.split())) assert 'statepoint' in doc assert doc['statepoint'] == {'a': 0} assert 'b' in doc assert doc['b'] == 0
def test_index(self): self.call("python -m signac init my_project".split()) self.call("python -m signac project --access".split()) project = signac.Project() project.open_job({"a": 0}).init() assert len(project) == 1 with pytest.deprecated_call(): assert len(list(project.index())) == 1 assert len(list(signac.index())) == 1 doc = json.loads(self.call("python -m signac index".split())) assert "statepoint" in doc assert doc["statepoint"] == {"a": 0} doc = json.loads(self.call("python -m signac project --index".split())) assert "statepoint" in doc assert doc["statepoint"] == {"a": 0} project.open_job({"a": 0}).document["b"] = 0 doc = json.loads(self.call("python -m signac index".split())) assert "statepoint" in doc assert doc["statepoint"] == {"a": 0} assert "b" in doc assert doc["b"] == 0