mirror of
https://github.com/OpenFreeEnergy/openfe.git
synced 2026-06-04 22:34:24 +08:00
* isort for docs and utils * isort for top-level openfe, analysis, setup * isort setup/ * isort storage/ * isort protocols * isort openn_afe * isort openmm_rfe * isort all protocols * apply isort to openfe/tests * apply isort to openfecli * apply isort to devtools/ * add TODO for setup init
81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
import pytest
|
|
|
|
from openfecli.fetching import FetchablePlugin, PkgResourceFetcher, URLFetcher
|
|
|
|
from .conftest import HAS_INTERNET
|
|
|
|
|
|
class FetcherTester:
|
|
@pytest.fixture
|
|
def fetcher(self):
|
|
raise NotImplementedError()
|
|
|
|
def test_resources(self):
|
|
raise NotImplementedError()
|
|
|
|
def test_plugin(self, fetcher):
|
|
# this is just a smoke test; individual plugins should test that
|
|
# they work
|
|
plugin = fetcher.plugin
|
|
assert isinstance(plugin, FetchablePlugin)
|
|
|
|
def test_call(self, fetcher, tmp_path):
|
|
# Here we just check that the machinery works. Each plugin should
|
|
# have a test to ensure that we're getting the right kind of file.
|
|
paths = [tmp_path / filename for _, filename in fetcher.resources]
|
|
for path in paths:
|
|
assert not path.exists()
|
|
|
|
fetcher(tmp_path)
|
|
|
|
for path in paths:
|
|
assert path.exists()
|
|
|
|
|
|
class TestURLFetcher(FetcherTester):
|
|
@pytest.fixture
|
|
def fetcher(self):
|
|
return URLFetcher(
|
|
resources=[("https://www.google.com/", "index.html")],
|
|
short_name="google",
|
|
short_help="The Goog",
|
|
requires_ofe=(0, 7, 0),
|
|
long_help="Google, an Alphabet company",
|
|
)
|
|
|
|
def test_resources(self, fetcher):
|
|
expected = [("https://www.google.com/", "index.html")]
|
|
assert list(fetcher.resources) == expected
|
|
|
|
@pytest.mark.skipif(not HAS_INTERNET, reason="Internet seems to be unavailable")
|
|
def test_call(self, fetcher, tmp_path):
|
|
super().test_call(fetcher, tmp_path)
|
|
|
|
@pytest.mark.skipif(not HAS_INTERNET, reason="Internet seems to be unavailable")
|
|
def test_without_trailing_slash(self, tmp_path):
|
|
fetcher = URLFetcher(
|
|
resources=[("https://www.google.com", "index.html")],
|
|
short_name="goog2",
|
|
short_help="more goog",
|
|
requires_ofe=(0, 7, 0),
|
|
long_help="What if you forget the trailing slash?",
|
|
)
|
|
|
|
self.test_call(fetcher, tmp_path)
|
|
|
|
|
|
class TestPkgResourceFetcher(FetcherTester):
|
|
@pytest.fixture
|
|
def fetcher(self):
|
|
return PkgResourceFetcher(
|
|
resources=[("openfecli.tests", "test_fetching.py")],
|
|
short_name="me",
|
|
short_help="download this file",
|
|
requires_ofe=(0, 7, 4),
|
|
long_help="whoa, meta.",
|
|
)
|
|
|
|
def test_resources(self, fetcher):
|
|
expected = [("openfecli.tests", "test_fetching.py")]
|
|
assert list(fetcher.resources) == expected
|