earwig / mwparserfromhell

A Python parser for MediaWiki wikicode
https://mwparserfromhell.readthedocs.io/
MIT License
741 stars 74 forks source link

Wikicode.matches() doesn't handle lower-case page title #302

Open roysmith opened 1 year ago

roysmith commented 1 year ago

mwparserfromhell==0.6.4 Python 3.9.13 MacOS Monterey

test_mainspace_match() passes, but test_talk_match() fails. They should both pass.

import mwparserfromhell as mwp

def test_mainspace_match():
    wikicode = mwp.parse("[[foo]]")
    link = wikicode.filter_wikilinks()[0]
    assert link.title.matches("Foo")

def test_talk_match():
    wikicode = mwp.parse("[[Talk:foo]]")
    link = wikicode.filter_wikilinks()[0]
    assert link.title.matches("Talk:Foo")

Test results:

(dyk-tools) Roys-MBP [temp] pytest test_matches.py
============================================================================= test session starts =============================================================================
platform darwin -- Python 3.9.13, pytest-7.2.0, pluggy-1.0.0
rootdir: /Users/roy/temp
plugins: mock-3.10.0, socket-0.5.1
collected 2 items                                                                                                                                                             

test_matches.py .F                                                                                                                                                      [100%]

================================================================================== FAILURES ===================================================================================
_______________________________________________________________________________ test_talk_match _______________________________________________________________________________

    def test_talk_match():
        wikicode = mwp.parse("[[Talk:foo]]")
        link = wikicode.filter_wikilinks()[0]
>       assert link.title.matches("Talk:Foo")
E       AssertionError: assert False
E        +  where False = <bound method Wikicode.matches of 'Talk:foo'>('Talk:Foo')
E        +    where <bound method Wikicode.matches of 'Talk:foo'> = 'Talk:foo'.matches
E        +      where 'Talk:foo' = '[[Talk:foo]]'.title

test_matches.py:11: AssertionError
=========================================================================== short test summary info ===========================================================================
FAILED test_matches.py::test_talk_match - AssertionError: assert False
========================================================================= 1 failed, 1 passed in 0.05s =========================================================================
lahwaacz commented 1 year ago

mwparserfromhell does not parse the link title. Note that your test actually depends on the wiki configuration (e.g. the namespace prefixes might be different and first-letter case-insensitiveness might be turned off). You can use my helper class from wiki-scripts.