Exemplo n.º 1
0
def test_notebooklet_create(monkeypatch):
    """Test method."""
    # Should run because required providers are loaded
    monkeypatch.setattr(data_providers, "GeoLiteLookup", GeoIPLiteMock)
    data_providers.init(query_provider="LocalData",
                        providers=["tilookup", "geolitelookup"])
    for _, nblt in nblts.iter_classes():
        new_nblt = nblt()
        check.is_instance(new_nblt, Notebooklet)
        check.is_none(new_nblt.result)

    # Should throw a warning because of unrecognized provider
    data_providers.init(query_provider="LocalData")
    with pytest.raises(MsticnbDataProviderError) as err:
        for _, nblt in nblts.iter_classes():
            curr_provs = nblt.metadata.req_providers
            bad_provs = [*curr_provs, "bad_provider"]
            try:
                nblt.metadata.req_providers = bad_provs
                new_nblt = nblt()
                check.is_instance(new_nblt, Notebooklet)
                check.is_none(new_nblt.result)
            finally:
                nblt.metadata.req_providers = curr_provs
    check.is_in("bad_provider", err.value.args[0])
    test_nb = TstNBSummary()
    check.is_not_none(test_nb.get_provider("LocalData"))
    with pytest.raises(MsticnbDataProviderError):
        test_nb.get_provider("otherprovider")
Exemplo n.º 2
0
    def test_notebooklet_create(self):
        """Test method."""
        test_with_geop = True
        try:
            geoip = GeoLiteLookup()
            if not geoip._api_key:
                test_with_geop = False
            del geoip
        except MsticpyUserConfigError:
            test_with_geop = False

        if test_with_geop:
            # Should run because required providers are loaded
            init(query_provider="LocalData",
                 providers=["tilookup", "geolitelookup"])
            for _, nblt in nblts.iter_classes():
                new_nblt = nblt()
                self.assertIsInstance(new_nblt, Notebooklet)
                self.assertIsNone(new_nblt.result)

        # Should throw a warning because of unrecognized provider
        init(query_provider="LocalData")
        with self.assertRaises(MsticnbDataProviderError) as err:
            for _, nblt in nblts.iter_classes():
                curr_provs = nblt.metadata.req_providers
                bad_provs = [*curr_provs, "bad_provider"]
                try:
                    nblt.metadata.req_providers = bad_provs
                    new_nblt = nblt()
                    self.assertIsInstance(new_nblt, Notebooklet)
                    self.assertIsNone(new_nblt.result)
                finally:
                    nblt.metadata.req_providers = curr_provs
        self.assertIn("bad_provider", err.exception.args[0])
        test_nb = TstNBSummary()
        self.assertIsNotNone(test_nb.get_provider("LocalData"))
        with self.assertRaises(MsticnbDataProviderError):
            test_nb.get_provider("otherprovider")
Exemplo n.º 3
0
 def test_class_methods(self):
     """Test method."""
     for _, nblt in nblts.iter_classes():
         self.assertIsNotNone(nblt.description())
         self.assertIsNotNone(nblt.name())
         self.assertGreater(len(nblt.all_options()), 0)
         self.assertGreater(len(nblt.default_options()), 0)
         self.assertGreater(len(nblt.keywords()), 0)
         self.assertGreater(len(nblt.entity_types()), 0)
         metadata = nblt.get_settings(print_settings=False)
         self.assertIsNotNone(metadata)
         self.assertIn("mod_name", metadata)
         self.assertIn("default_options", metadata)
         self.assertIn("keywords", metadata)
Exemplo n.º 4
0
    def test_class_doc(self):
        """Test class documentation."""
        for _, nblt in nblts.iter_classes():
            html_doc = nblt.get_help()
            self.assertNotEqual(html_doc, "No documentation available.")
            self.assertGreater(len(html_doc), 100)

            md_doc = nblt.get_help(fmt="md")
            html_doc2 = markdown(md_doc)
            self.assertEqual(html_doc, html_doc2)

            _html_parser = etree.HTMLParser(recover=False)
            elem_tree = etree.parse(StringIO(html_doc), _html_parser)
            self.assertIsNotNone(elem_tree)
Exemplo n.º 5
0
def test_class_methods():
    """Test method."""
    for _, nblt in nblts.iter_classes():
        check.is_not_none(nblt.description())
        check.is_not_none(nblt.name())
        all_opts = len(nblt.all_options())
        check.greater_equal(all_opts, len(nblt.default_options()))
        check.greater(len(nblt.keywords()), 0)
        check.greater(len(nblt.entity_types()), 0)
        metadata = nblt.get_settings(print_settings=False)
        check.is_not_none(metadata)
        check.is_in("mod_name", metadata)
        check.is_in("default_options", metadata)
        check.is_in("keywords", metadata)
Exemplo n.º 6
0
def test_class_doc():
    """Test class documentation."""
    for _, nblt in nblts.iter_classes():
        html_doc = nblt.get_help()
        check.not_equal(html_doc, "No documentation available.")
        check.greater(len(html_doc), 100)

        md_doc = nblt.get_help(fmt="md")
        html_doc2 = markdown(md_doc)
        check.equal(html_doc, html_doc2)

        _html_parser = etree.HTMLParser(recover=False)
        elem_tree = etree.parse(StringIO(html_doc), _html_parser)
        check.is_not_none(elem_tree)