MaRDI4NFDI / python-zbMathRest2Oai

Read data from the zbMATH Open API https://api.zbmath.org/docs and feed it to the OAI-PMH server https://oai.portal.mardi4nfdi.de/oai/
GNU General Public License v3.0
4 stars 0 forks source link

Fix failing tests #96

Closed physikerwelt closed 1 month ago

physikerwelt commented 1 month ago

Describe the issue

=================================== FAILURES ===================================
_________________________ PlainXmlTest.test_similarity _________________________

self = <test_metadata_article_OpenAire.PlainXmlTest testMethod=test_similarity>

    def test_similarity(self):

>       dom = ET.parse('../../test/data/articles/plain.xml')

test/test_metadata_article_OpenAire.py:33: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/lxml/etree.pyx:3589: in lxml.etree.parse
    ???
src/lxml/parser.pxi:1958: in lxml.etree._parseDocument
    ???
src/lxml/parser.pxi:1984: in lxml.etree._parseDocumentFromURL
    ???
src/lxml/parser.pxi:1887: in lxml.etree._parseDocFromFile
    ???
src/lxml/parser.pxi:1200: in lxml.etree._BaseParser._parseDocFromFile
    ???
src/lxml/parser.pxi:633: in lxml.etree._ParserContext._handleParseResultDoc
    ???
src/lxml/parser.pxi:743: in lxml.etree._handleParseResult
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   OSError: Error reading file '../../test/data/articles/plain.xml': failed to load external entity "../../test/data/articles/plain.xml"

src/lxml/parser.pxi:670: OSError
_________________________ PlainXmlTest.test_similarity _________________________

self = <test_metadata_software_Codemeta.PlainXmlTest testMethod=test_similarity>

    def test_similarity(self):

>       dom = ET.parse('test/data/software/software_with_swhid.xml')

test/test_metadata_software_Codemeta.py:33: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/lxml/etree.pyx:3589: in lxml.etree.parse
    ???
src/lxml/parser.pxi:1958: in lxml.etree._parseDocument
    ???
src/lxml/parser.pxi:1984: in lxml.etree._parseDocumentFromURL
    ???
src/lxml/parser.pxi:1887: in lxml.etree._parseDocFromFile
    ???
src/lxml/parser.pxi:1200: in lxml.etree._BaseParser._parseDocFromFile
    ???
src/lxml/parser.pxi:633: in lxml.etree._ParserContext._handleParseResultDoc
    ???
src/lxml/parser.pxi:743: in lxml.etree._handleParseResult
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   OSError: Error reading file 'test/data/software/software_with_swhid.xml': failed to load external entity "test/data/software/software_with_swhid.xml"

src/lxml/parser.pxi:670: OSError
_________________________ PlainXmlTest.test_similarity _________________________

self = <test_software_metadata.PlainXmlTest testMethod=test_similarity>

    def test_similarity(self):
        real_string = getAsXml.final_xml2(API_SOURCE,'')[0]['2']
        real_string = [line for line in real_string.splitlines() if line.strip() != '']
        real_string = '\n'.join(real_string)
        ref_location = os.path.join(os.path.dirname(__file__), 'data/software/plain.xml')
        with open(ref_location) as f:
            expected_string = f.read()

            diff = main.diff_texts(expected_string, real_string, {
                'ratio_mode': 'fast',
                'F': 1,
            })
            essentials = list(filter(lambda e: not isinstance(e, MoveNode), diff))
>           self.assertLessEqual(len(essentials), 0)
E           AssertionError: 11 not less than or equal to 0

test/test_software_metadata.py:26: AssertionError
=========================== short test summary info ============================
FAILED test/test_metadata_article_OpenAire.py::PlainXmlTest::test_similarity - OSError: Error reading file '../../test/data/articles/plain.xml': failed to load external entity "../../test/data/articles/plain.xml"
FAILED test/test_metadata_software_Codemeta.py::PlainXmlTest::test_similarity - OSError: Error reading file 'test/data/software/software_with_swhid.xml': failed to load external entity "test/data/software/software_with_swhid.xml"
FAILED test/test_software_metadata.py::PlainXmlTest::test_similarity - AssertionError: 11 not less than or equal to 0
========================= 3 failed, 8 passed in 6.48s ==========================
Shirazos7 commented 1 month ago

this commit should fix the issue 70332a1

it just needed to adjust the paths of the file the unittest should work now with no problems

============================= test session starts ============================= collecting ... collected 1 item

test_metadata_article_OpenAire.py::PlainXmlTest::test_similarity PASSED [100%]

============================== 1 passed in 0.18s ==============================

Process finished with exit code 0

Shirazos7 commented 1 month ago

with this commit the unittest should also work without any problems

14e3d77

i created a branch called fixing-unittest and i will delete the branch now

============================= test session starts ============================= collecting ... collected 1 item

test_metadata_software_Codemeta.py::PlainXmlTest::test_similarity PASSED [100%]

============================== 1 passed in 0.09s ==============================

Process finished with exit code 0

physikerwelt commented 1 month ago

https://github.com/MaRDI4NFDI/python-zbMathRest2Oai/actions shows failing tests

Shirazos7 commented 1 month ago

when i run each test by its own they all work properly on my local machine . i will check it and work on it to fix the problem

physikerwelt commented 1 month ago

Maybe some files are missing in the repo? Can you double check the following test


    def test_api_version_matches(self):
        url = "https://api.zbmath.org/openapi.json"
        expected_version = "1.5.4"
        actual_version = get_api_version(url)
>       self.assertEqual(actual_version, expected_version,
                         f"Expected API version {expected_version}, but got {actual_version}")
E       AssertionError: '1.5.8' != '1.5.4'
E       - 1.5.8
E       ?     ^
E       + 1.5.4
E       ?     ^
E        : Expected API version 1.5.4, but got 1.5.8
Shirazos7 commented 1 month ago

yes the api version is old in the unittest i updated it from 1.5.4 to 1.5.8 this is the commit 5c75ab2 i can make a pull request when you agree with it .

Shirazos7 commented 1 month ago

and i will check the files in the repo and try to figure out why the tests are failing.

physikerwelt commented 1 month ago

Read the test output; it shows which files are missing.

physikerwelt commented 1 month ago

test/data/software/software_with_swhid.xml is missing