""" Unit tests for the metadata parts. """ import logging import sys from lxml import html from lxml.etree import XPath from trafilatura.json_metadata import normalize_authors, normalize_json from trafilatura.metadata import check_authors, extract_metadata, extract_metainfo, extract_url, normalize_tags logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) def test_titles(): '''Test the extraction of titles''' tests = [ ('
') assert metadata.title == '- Home' metadata = extract_metadata('
') assert metadata.title == "My Title" # TODO: and metadata.sitename == "My Website" def test_authors(): '''Test the extraction of author names''' # normalization assert normalize_authors(None, 'abc') == 'Abc' assert normalize_authors(None, 'Steve Steve 123') == 'Steve Steve' assert normalize_authors(None, 'By Steve Steve') == 'Steve Steve' assert normalize_json('Test \\nthis') == 'Test this' assert normalize_json('\\uD800\\uDC00Hello\\uDBFF\\uDFFF') == 'Hello' assert normalize_json('Test \u3010ABC\u3011') == 'Test 【ABC】' assert normalize_json("Seán Federico O'Murchú") == "Seán Federico O'Murchú" # blacklist metadata = extract_metadata('