def test_get_conda_info(self): conda_info = _annotation.get_conda_info() conda_info_keys = sorted(list(conda_info.keys())) self.assertTrue('status' in conda_info_keys) if conda_info['status'] != 'Failed': self.assertListEqual(self.ref_conda_info_keys, conda_info_keys) self.assertTrue(conda_info['status'] == 'Succeeded')
def test_get_conda_info(self): conda_info = _annotation.get_conda_info() conda_info_keys = sorted(list(conda_info.keys())) self.assertTrue('status' in conda_info_keys) if 'Failed' not in conda_info['status']: import conda if _parse_version(conda.__version__) >= _parse_version('4.2.0'): self.assertListEqual(self.ref_conda_420_info_keys, conda_info_keys) else: self.assertListEqual(self.ref_conda_410_info_keys, conda_info_keys) self.assertTrue(conda_info['status'] == 'Succeeded')
def annotate_database(h5file): """ Annotate an HDF5 database with information about Magni and the platform. The annotation consists of a group in the root of the `h5file` having nodes that each provide information about Magni or the platform on which this function is run. Parameters ---------- h5file : tables.file.File The handle to the HDF5 database that should be annotated. See Also -------- magni.reproducibility._annotation.get_conda_info : Conda annotation magni.reproducibility._annotation.get_git_revision : Git annotation magni.reproducibility._annotation.get_platform_info : Platform annotation magni.reproducibility._annotation.get_datetime : Date and time annotation magni.reproducibility._annotation.get_magni_config : Magni config annotation magni.reproducibility._annotation.get_magni_info : Magni info annotation Notes ----- The annotations of the database includes the following: * conda_info - Information about Continuum Anacononda install * git_revision - Git revision and tag of Magni * platform_info - Information about the current platform (system) * datetime - The current date and time * magni_config - Infomation about the current configuration of Magni * magni_info - Information from `help(magni)` Examples -------- Annotate the database named 'db.hdf5': >>> import magni >>> from magni.reproducibility.io import annotate_database >>> with magni.utils.multiprocessing.File('db.hdf5', mode='a') as h5file: ... annotate_database(h5file) """ @_decorate_validation def validate_input(): _generic('h5file', tables.file.File) validate_input() annotations = { 'conda_info': json.dumps(_annotation.get_conda_info()), 'git_revision': json.dumps(_annotation.get_git_revision()), 'platform_info': json.dumps(_annotation.get_platform_info()), 'datetime': json.dumps(_annotation.get_datetime()), 'magni_config': json.dumps(_annotation.get_magni_config()), 'magni_info': json.dumps(_annotation.get_magni_info()) } try: annotations_group = h5file.create_group('/', 'annotations') for annotation in annotations: h5file.create_array(annotations_group, annotation, obj=annotations[annotation].encode()) h5file.flush() except tables.NodeError: raise tables.NodeError('The database has already been annotated. ' + 'Remove the existing annotation prior to ' + '(re)annotating the database.')
def annotate_database(h5file): """ Annotate an HDF5 database with information about Magni and the platform. The annotation consists of a group in the root of the `h5file` having nodes that each provide information about Magni or the platform on which this function is run. Parameters ---------- h5file : tables.file.File The handle to the HDF5 database that should be annotated. See Also -------- magni.reproducibility._annotation.get_conda_info : Conda annotation magni.reproducibility._annotation.get_git_revision : Git annotation magni.reproducibility._annotation.get_platform_info : Platform annotation magni.reproducibility._annotation.get_datetime : Date and time annotation magni.reproducibility._annotation.get_magni_config : Magni config annotation magni.reproducibility._annotation.get_magni_info : Magni info annotation Notes ----- The annotations of the database includes the following: * conda_info - Information about Continuum Anacononda install * git_revision - Git revision and tag of Magni * platform_info - Information about the current platform (system) * datetime - The current date and time * magni_config - Infomation about the current configuration of Magni * magni_info - Information from `help(magni)` Examples -------- Annotate the database named 'db.hdf5': >>> from magni.reproducibility.io import annotate_database >>> with magni.utils.multiprocessing.File('db.hdf5', mode='a') as h5file: ... annotate_database(h5file) """ _validate_annotate_database(h5file) annotations = {'conda_info': json.dumps(_annotation.get_conda_info()), 'git_revision': json.dumps(_annotation.get_git_revision()), 'platform_info': json.dumps( _annotation.get_platform_info()), 'datetime': json.dumps(_annotation.get_datetime()), 'magni_config': json.dumps(_annotation.get_magni_config()), 'magni_info': json.dumps(_annotation.get_magni_info())} try: annotations_group = h5file.create_group('/', 'annotations') for annotation in annotations: h5file.create_array(annotations_group, annotation, obj=annotations[annotation].encode()) h5file.flush() except tables.NodeError: raise tables.NodeError('The database has already been annotated. ' + 'Remove the existing annotation prior to ' + '(re)annotating the database.')