1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#########################################################################
# MacSyLib - Python library to detect macromolecular systems #
# in prokaryotes protein dataset using systems modelling #
# and similarity search. #
# #
# Authors: Sophie Abby, Bertrand Neron #
# Copyright (c) 2014-2025 Institut Pasteur (Paris) and CNRS. #
# See the COPYRIGHT file for details #
# #
# This file is part of MacSyLib package. #
# #
# MacSyLib is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# MacSyLib is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details . #
# #
# You should have received a copy of the GNU General Public License #
# along with MacSyLib (COPYING). #
# If not, see <https://www.gnu.org/licenses/>. #
#########################################################################
import os
import shutil
import tempfile
import yaml
from macsylib.metadata import Metadata, Maintainer
from tests import MacsyTest
class TestMetadata(MacsyTest):
def setUp(self) -> None:
self._tmp_dir = tempfile.TemporaryDirectory(prefix='test_msl_metadata_')
self.tmpdir = self._tmp_dir.name
if os.path.exists(self.tmpdir) and os.path.isdir(self.tmpdir):
shutil.rmtree(self.tmpdir)
os.makedirs(self.tmpdir)
def tearDown(self) -> None:
self._tmp_dir.cleanup()
def test_init(self):
maintainer = Maintainer(name='joe', email='joe@bar.org')
short_desc = 'this is a short description'
meta = Metadata(maintainer, short_desc)
self.assertEqual(meta.maintainer, maintainer)
self.assertEqual(meta.short_desc, short_desc)
self.assertIsNone(meta.vers)
self.assertEqual(meta.license, '')
def test_save(self):
for yml_name in ('metadata_no_license.yml',
):
with self.subTest(yml_name=yml_name):
meta_path = self.find_data('pack_metadata', yml_name)
meta = Metadata.load(meta_path)
saved_path = os.path.join(self.tmpdir, 'metadata.yml')
meta.save(saved_path)
with open(saved_path) as saved_file:
saved_yaml = yaml.safe_load(saved_file)
with open(meta_path) as ref_file:
ref_yaml = yaml.safe_load(ref_file)
self.assertDictEqual(ref_yaml, saved_yaml)
|