コード例 #1
0
    def test_help(self):
        fake_pack_path = self.create_fake_package('fake_model', license=False)
        pack = package.Package(fake_pack_path)

        receive_help = pack.help()
        self.assertEqual(receive_help, "# This a README\n")

        os.unlink(os.path.join(fake_pack_path, 'README'))
        pack = package.Package(fake_pack_path)
        receive_help = pack.help()
        self.assertEqual(receive_help, "No help available for package 'fake_model'.")
コード例 #2
0
    def test_check_structure_no_metadata(self):
        fake_pack_path = self.create_fake_package('fake_model', metadata=False)
        pack = package.Package(fake_pack_path)
        errors, warnings = pack._check_structure()

        self.assertListEqual(errors, ["The package 'fake_model' have no 'metadata.yml'."])
        self.assertListEqual(warnings, [])
コード例 #3
0
    def test_check_structure_no_readme(self):
        fake_pack_path = self.create_fake_package('fake_model', readme=False)
        pack = package.Package(fake_pack_path)
        errors, warnings = pack._check_structure()

        self.assertEqual(errors, [])
        self.assertEqual(warnings, ["The package 'fake_model' have not any README file."])
コード例 #4
0
 def test_init(self):
     fake_pack_path = self.create_fake_package('fake_model')
     pack = package.Package(fake_pack_path)
     self.assertEqual(pack.path, fake_pack_path)
     self.assertEqual(pack.readme, os.path.join(fake_pack_path, 'README'))
     self.assertEqual(pack.name, 'fake_model')
     self.assertEqual(pack.metadata_path, os.path.join(fake_pack_path, 'metadata.yml'))
コード例 #5
0
    def test_check_structure_no_license(self):
        fake_pack_path = self.create_fake_package('fake_model', license=False)
        pack = package.Package(fake_pack_path)
        errors, warnings = pack._check_structure()

        self.assertEqual(errors, [])
        self.assertEqual(warnings, ["The package 'fake_model' have not any LICENSE file. "
                                    "May be you have not right to use it."])
コード例 #6
0
 def test_check_model_consistency_bad_definitions(self):
     fake_pack_path = self.create_fake_package('fake_model', bad_definitions=True)
     pack = package.Package(fake_pack_path)
     with self.catch_log(log_name='macsypy'):
         errors, warnings = pack._check_model_consistency()
     self.assertEqual(warnings, [])
     self.assertEqual(errors, ["fake_model/model_3: min_genes_required '1' must be greater or equal than "
                               "min_mandatory_genes_required '2'"])
コード例 #7
0
    def test_check_model_consistency(self):
        fake_pack_path = self.create_fake_package('fake_model')
        pack = package.Package(fake_pack_path)
        with self.catch_log(log_name='macsypy'):
            errors, warnings = pack._check_model_consistency()

        self.assertEqual(warnings, [])
        self.assertEqual(errors, [])
コード例 #8
0
 def test_check_model_conf_bad_conf(self):
     fake_pack_path = self.create_fake_package('fake_model', conf=False, bad_conf=True)
     pack = package.Package(fake_pack_path)
     with self.catch_log(log_name='macsypy'):
         errors, warnings = pack._check_model_conf()
     self.maxDiff =None
     self.assertListEqual(errors, [f"The model configuration file '{fake_pack_path}/model_conf.xml' "
                                   f"cannot be parsed: could not convert string to float: 'FOO'"])
     self.assertListEqual(warnings, [])
コード例 #9
0
    def test_check_model_consistency_extra_profile(self):
        fake_pack_path = self.create_fake_package('fake_model')
        pack = package.Package(fake_pack_path)
        open(os.path.join(fake_pack_path, 'profiles', 'extra_profile.hmm'), 'w').close()
        with self.catch_log(log_name='macsypy'):
            errors, warnings = pack._check_model_consistency()

        self.assertEqual(warnings, ['The extra_profile profiles are not referenced in any definitions.'])
        self.assertEqual(errors, [])
コード例 #10
0
    def test_check_structure_bad_path(self):
        foobar = os.path.join(self.tmpdir, "foobar")
        pack = package.Package(foobar)
        errors, warnings = pack._check_structure()
        self.assertListEqual(errors, ["The package 'foobar' does not exists."])
        self.assertListEqual(warnings, [])

        open(foobar, 'w').close()
        errors, warnings = pack._check_structure()
        self.assertListEqual(errors, ["'foobar' is not a directory "])
        self.assertListEqual(warnings, [])
コード例 #11
0
    def test_check_model_consistency_lack_one_profile(self):
        fake_pack_path = self.create_fake_package('fake_model', skip_hmm=['flgB', 'fliE'])
        pack = package.Package(fake_pack_path)
        with self.catch_log(log_name='macsypy'):
            errors, warnings = pack._check_model_consistency()

        self.assertEqual(warnings, [])
        self.assertSetEqual(set(errors),
                            set(["'fake_model/flgB': No such profile",
                                 "'fake_model/fliE': No such profile"])
                            )
コード例 #12
0
 def test_find_readme(self):
     fake_pack_path = self.create_fake_package('fake_model')
     pack = package.Package(fake_pack_path)
     for ext in ('', '.rst', '.md'):
         readme_path = os.path.join(pack.path, 'README' + ext)
         os.rename(pack.readme, readme_path)
         pack.readme = readme_path
         self.assertEqual(pack._find_readme(), readme_path)
     readme_path = os.path.join(pack.path, 'README.foo')
     os.rename(pack.readme, readme_path)
     self.assertIsNone(pack._find_readme())
コード例 #13
0
    def test_check_structure_no_profiles(self):
        fake_pack_path = self.create_fake_package('fake_model', profiles=False)
        pack = package.Package(fake_pack_path)
        errors, warnings = pack._check_structure()

        self.assertListEqual(errors, ["The package 'fake_model' have no 'profiles' directory."])
        self.assertListEqual(warnings, [])

        open(os.path.join(pack.path, 'profiles'), 'w').close()
        errors, warnings = pack._check_structure()
        self.assertListEqual(errors, ["'/tmp/macsy_test_package/fake_model/profiles' is not a directory."])
        self.assertListEqual(warnings, [])
コード例 #14
0
 def test_check(self):
     fake_pack_path = self.create_fake_package('fake_model')
     load_metadata_meth = package.Package._load_metadata
     bad_meta_data = {"short_desc": "this is a short description of the repos",
                      "doc": "http://link/to/the/documentation",
                      "copyright": "2019, Institut Pasteur, CNRS"
                      }
     try:
         package.Package._load_metadata = lambda x: bad_meta_data
         pack = package.Package(fake_pack_path)
         errors, warnings = pack.check()
     finally:
         package.Package._load_metadata = load_metadata_meth
     self.assertListEqual(errors,
                          ["field 'maintainer' is mandatory in metadata_path.",
                           "field 'vers' is mandatory in metadata_path."])
     self.assertListEqual(warnings,
                          ["It's better if the field 'cite' is setup in metadata_path file",
                           "It's better if the field 'license' is setup in metadata_path file"])
コード例 #15
0
    def test_check_metadata(self):
        fake_pack_path = self.create_fake_package('fake_model')
        pack = package.Package(fake_pack_path)
        errors, warnings = pack._check_metadata()
        self.assertEqual(errors, [])
        self.assertEqual(warnings, [])

        load_metadata_meth = package.Package._load_metadata

        #################
        # No maintainer #
        #################
        no_auth_meta_data = self.metadata.copy()
        del no_auth_meta_data['maintainer']
        try:
            package.Package._load_metadata = lambda x: no_auth_meta_data
            pack = package.Package(fake_pack_path)
            errors, warnings = pack._check_metadata()
        finally:
            package.Package._load_metadata = load_metadata_meth
        self.assertEqual(errors, ["field 'maintainer' is mandatory in metadata_path."])
        self.assertEqual(warnings, [])

        #################
        # No short desc #
        #################
        no_short_desc_metadata = self.metadata.copy()
        del no_short_desc_metadata['short_desc']
        try:
            package.Package._load_metadata = lambda x: no_short_desc_metadata
            pack = package.Package(fake_pack_path)
            errors, warnings = pack._check_metadata()
        finally:
            package.Package._load_metadata = load_metadata_meth
        self.assertEqual(errors, ["field 'short_desc' is mandatory in metadata_path."])
        self.assertEqual(warnings, [])

        ###########
        # No vers #
        ###########
        no_vers_metadata = self.metadata.copy()
        del no_vers_metadata['vers']
        try:
            package.Package._load_metadata = lambda x: no_vers_metadata
            pack = package.Package(fake_pack_path)
            errors, warnings = pack._check_metadata()
        finally:
            package.Package._load_metadata = load_metadata_meth
        self.assertEqual(errors, ["field 'vers' is mandatory in metadata_path."])
        self.assertEqual(warnings, [])

        ###########
        # No cite #
        ###########
        no_cite_metadata = self.metadata.copy()
        del no_cite_metadata['cite']
        try:
            package.Package._load_metadata = lambda x: no_cite_metadata
            pack = package.Package(fake_pack_path)
            errors, warnings = pack._check_metadata()
        finally:
            package.Package._load_metadata = load_metadata_meth
        self.assertEqual(errors, [])
        self.assertEqual(warnings, ["It's better if the field 'cite' is setup in metadata_path file"])

        ##########
        # No doc #
        ##########
        no_doc_metadata = self.metadata.copy()
        del no_doc_metadata['doc']
        try:
            package.Package._load_metadata = lambda x: no_doc_metadata
            pack = package.Package(fake_pack_path)
            errors, warnings = pack._check_metadata()
        finally:
            package.Package._load_metadata = load_metadata_meth
        self.assertEqual(errors, [])
        self.assertEqual(warnings, ["It's better if the field 'doc' is setup in metadata_path file"])

        ##############
        # No license #
        ##############
        no_license_metadata = self.metadata.copy()
        del no_license_metadata['license']
        try:
            package.Package._load_metadata = lambda x: no_license_metadata
            pack = package.Package(fake_pack_path)
            errors, warnings = pack._check_metadata()
        finally:
            package.Package._load_metadata = load_metadata_meth
        self.assertEqual(errors, [])
        self.assertEqual(warnings, ["It's better if the field 'license' is setup in metadata_path file"])

        ################
        # No copyright #
        ################
        no_copyright_metadata = self.metadata.copy()
        del no_copyright_metadata['copyright']
        try:
            package.Package._load_metadata = lambda x: no_copyright_metadata
            pack = package.Package(fake_pack_path)
            errors, warnings = pack._check_metadata()
        finally:
            package.Package._load_metadata = load_metadata_meth
        self.assertEqual(errors, [])
        self.assertEqual(warnings, ["It's better if the field 'copyright' is setup in metadata_path file"])

        ##################
        # No maintainer name #
        ##################
        # this test must the last of the set
        # because we remove a key in maintainer value
        # the copy is a shallow copy
        # so maintainer value is a reference to the good_metadata[maintainer]
        # side effect
        no_auth_name_meta_data = self.metadata.copy()
        del no_auth_name_meta_data['maintainer']['name']
        try:
            package.Package._load_metadata = lambda x: no_auth_name_meta_data
            pack = package.Package(fake_pack_path)
            errors, warnings = pack._check_metadata()
        finally:
            package.Package._load_metadata = load_metadata_meth
        self.assertEqual(errors, ["field 'maintainer.name' is mandatory in metadata_path."])
        self.assertEqual(warnings, [])
コード例 #16
0
 def test_check_structure(self):
     fake_pack_path = self.create_fake_package('fake_model')
     pack = package.Package(fake_pack_path)
     errors, warnings = pack._check_structure()
     self.assertListEqual(errors, [])
     self.assertListEqual(warnings, [])
コード例 #17
0
 def test_metadata(self):
     fake_pack_path = self.create_fake_package('fake_model')
     pack = package.Package(fake_pack_path)
     self.assertDictEqual(pack.metadata, self.metadata)
     self.assertDictEqual(pack.metadata, self.metadata)
コード例 #18
0
    def test_info(self):
        fake_pack_path = self.create_fake_package('fake_model', license=False)
        pack = package.Package(fake_pack_path)

        info = pack.info()
        expected_info = """
fake_model (0.0b2)

maintainer: auth_name <*****@*****.**>

this is a short description of the repos

how to cite:
\t- bla bla
\t- link to publication
\t- ligne 1
\t  ligne 2
\t  ligne 3 et bbbbb

documentation
\thttp://link/to/the/documentation

This data are released under CC BY-NC-SA 4.0 (https://creativecommons.org/licenses/by-nc-sa/4.0/)
copyright: 2019, Institut Pasteur, CNRS
"""
        self.assertEqual(info, expected_info)

        load_metadata_meth = package.Package._load_metadata
        ###########
        # No cite #
        ###########
        no_cite_metadata = self.metadata.copy()
        del no_cite_metadata['cite']
        try:
            package.Package._load_metadata = lambda x: no_cite_metadata
            pack = package.Package(fake_pack_path)
            info = pack.info()
        finally:
            package.Package._load_metadata = load_metadata_meth
        expected_info = """
fake_model (0.0b2)

maintainer: auth_name <*****@*****.**>

this is a short description of the repos

how to cite:
\t- No citation available

documentation
\thttp://link/to/the/documentation

This data are released under CC BY-NC-SA 4.0 (https://creativecommons.org/licenses/by-nc-sa/4.0/)
copyright: 2019, Institut Pasteur, CNRS
"""
        self.assertEqual(info, expected_info)

        ##########
        # No doc #
        ##########
        no_doc_metadata = self.metadata.copy()
        del no_doc_metadata['doc']
        try:
            package.Package._load_metadata = lambda x: no_doc_metadata
            pack = package.Package(fake_pack_path)
            info = pack.info()
        finally:
            package.Package._load_metadata = load_metadata_meth
        expected_info = """
fake_model (0.0b2)

maintainer: auth_name <*****@*****.**>

this is a short description of the repos

how to cite:
\t- bla bla
\t- link to publication
\t- ligne 1
\t  ligne 2
\t  ligne 3 et bbbbb

documentation
\tNo documentation available

This data are released under CC BY-NC-SA 4.0 (https://creativecommons.org/licenses/by-nc-sa/4.0/)
copyright: 2019, Institut Pasteur, CNRS
"""
        self.assertEqual(info, expected_info)

        ##############
        # No license #
        ##############
        no_license_metadata = self.metadata.copy()
        del no_license_metadata['license']
        try:
            package.Package._load_metadata = lambda x: no_license_metadata
            pack = package.Package(fake_pack_path)
            info = pack.info()
        finally:
            package.Package._load_metadata = load_metadata_meth
        expected_info = """
fake_model (0.0b2)

maintainer: auth_name <*****@*****.**>

this is a short description of the repos

how to cite:
\t- bla bla
\t- link to publication
\t- ligne 1
\t  ligne 2
\t  ligne 3 et bbbbb

documentation
\thttp://link/to/the/documentation

This data are released under No license available
copyright: 2019, Institut Pasteur, CNRS
"""
        self.assertEqual(info, expected_info)
コード例 #19
0
 def test_check_model_conf_no_conf(self):
     fake_pack_path = self.create_fake_package('fake_model', conf=False)
     pack = package.Package(fake_pack_path)
     errors, warnings = pack._check_model_conf()
     self.assertListEqual(errors, [])
     self.assertListEqual(warnings, [])