def test_batchjson_metadata(self): """BatchJsonProcess should work with metadata --batch --json""" metadata = GitAnnexBatchJsonProcess( ['metadata', '--batch', '--json'], str(self.tempdir), ) def expected(key, file=None): return { 'command': 'metadata', 'note': '', 'success': True, 'key': key, 'file': file, 'fields': {}, } for f, k in self.keys.items(): with self.subTest(file=f): output = metadata({"key": k}) for jk, jv in expected(k).items(): self.assertEqual(jv, output[jk]) output = metadata({"file": f}) for jk, jv in expected(k, f).items(): self.assertEqual(jv, output[jk])
def _enumerate(self): subproc = GitAnnexBatchJsonProcess(['whereis', '--json', '--all'], self.workdir) while True: result = subproc({}) if not result: break if 'command' in result and result['command'] == 'whereis': if result['success'] != True: result['command'] = 'whereis --json --all' raise Exception( result, "This may be due to a git-annex remote error that displays only for this command line." ) yield (result['key'], result['whereis'])
def test_batchjson_restarts(self): """BatchJsonProcess should auto-restart dead processes""" metadata = GitAnnexBatchJsonProcess( ['metadata', '--batch', '--json'], str(self.tempdir), ) for f, k in self.keys.items(): with self.subTest(file=f): file_meta = metadata({'file': f}) key_meta = metadata({'key': k}) # Invalid query with self.assertRaises(subprocess.CalledProcessError): metadata({'key': 'invalid'}) self.assertEqual(file_meta, metadata({'file': f})) self.assertEqual(key_meta, metadata({'key': k}))
def test_batchjson_metadata(self): """BatchJsonProcess should work with metadata --batch --json""" metadata = GitAnnexBatchJsonProcess( ['metadata', '--batch', '--json'], str(self.tempdir), ) def meta(key, file=None): return { 'command': 'metadata', 'note': '', 'success': True, 'key': key, 'file': file, 'fields': {}, } for f, k in self.keys.items(): with self.subTest(file=f): self.assertEqual(metadata({'key': k}), meta(k)) self.assertEqual(metadata({'file': f}), meta(k, f))