From cb1b598d732a08e9915fc415e8bf805b030bf480 Mon Sep 17 00:00:00 2001 From: Hrishikesh Terdalkar Date: Thu, 17 Feb 2022 00:37:41 +0530 Subject: [PATCH] test(corpus): add test for corpus setup, remove duplicate fixtures --- tests/test_corpus.py | 59 ++++++++------------------------------------ 1 file changed, 10 insertions(+), 49 deletions(-) diff --git a/tests/test_corpus.py b/tests/test_corpus.py index 8ceb97d..18f6028 100644 --- a/tests/test_corpus.py +++ b/tests/test_corpus.py @@ -4,61 +4,12 @@ import pytest -from pycdsl.corpus import SERVER_URL, CDSLCorpus from pycdsl.lexicon import CDSLDict from pycdsl.models import Entry ############################################################################### -@pytest.fixture(scope="package") -def cdsl_homepage(): - """Fixture for CDSL Homepage""" - import requests - return requests.get(SERVER_URL) - - -@pytest.fixture(scope="package") -def default_path(tmp_path_factory): - return tmp_path_factory.mktemp("cdsl_data") - - -@pytest.fixture(scope="package") -def default_corpus_options(default_path): - return { - 'data_dir': default_path - } - - -@pytest.fixture(scope="package") -def default_corpus(default_corpus_options): - return CDSLCorpus(**default_corpus_options) - - -@pytest.fixture(scope="package") -def available_dicts(default_corpus): - return default_corpus.get_available_dicts() - - -@pytest.fixture(scope="package") -def installation_list(): - return ["WIL"] - - -@pytest.fixture(scope="package") -def ready_corpus(default_corpus, installation_list): - default_corpus.setup(installation_list) - return default_corpus - - -@pytest.fixture(scope="package") -def installed_dicts(ready_corpus): - return ready_corpus.get_installed_dicts() - - -############################################################################### - - def test_homepage_content(cdsl_homepage): from bs4 import BeautifulSoup soup = BeautifulSoup(cdsl_homepage.content.decode(), "html.parser") @@ -75,6 +26,16 @@ def test_available_dicts(available_dicts): assert isinstance(cdsl_dict, CDSLDict) +def test_corpus_setup(default_corpus, installation_list): + assert default_corpus.setup(installation_list) is True + + +def test_corpus_setup_error_1(default_corpus, installation_list, caplog): + with pytest.raises(ValueError) as exc_info: + default_corpus.setup(installation_list[0]) + assert exc_info.type is ValueError + + def test_installed_dicts(installed_dicts, installation_list): assert isinstance(installed_dicts, dict) assert list(installed_dicts) == installation_list