def test_open_file(): with open(os.path.join(TEST_DIR, 'empty.html')) as f: p = Parser(doc=f) assert_true(p.__doc__ is not None) assert_true(type(p) is not None) assert_true(type(p.to_dict()) is dict)
def test_person_with_url(): p = Parser(doc=open("test/examples/person_with_url.html")) result = p.to_dict() assert_equal(result["items"][0]["properties"]["name"], ['Tom Morris']) assert_equal(result["items"][0]["properties"]["url"], ['http://tommorris.org/'])
def test_person_with_url(): p = Parser(doc=open("test/examples/person_with_url.html")) result = p.to_dict() assert_equal(result["items"][0]["properties"]["name"], ['Tom Morris']) assert_equal(result["items"][0]["properties"]["url"], ['http://tommorris.org/'])
def test_doc_tag_backcompat(): # test that strings, BS doc and BS tags are all parsed and in the latter cases copies are made and are modified by backcompat doc = '''<article class="hentry"></article>''' soup = BeautifulSoup(doc) parse_string = Parser(doc).to_dict() assert_true('h-entry' in parse_string['items'][0]['type']) p = Parser(soup) assert_true('h-entry' in p.to_dict()['items'][0]['type']) assert_false(soup is p.__doc__) assert_false(soup == p.__doc__) p = Parser(soup.article) assert_true('h-entry' in p.to_dict()['items'][0]['type']) assert_false(soup.article is p.__doc__) assert_false(soup.article == p.__doc__)
def test_empty(): p = Parser() assert_true(type(p) is not None) assert_true(type(p.to_dict()) is dict)
def parse_fixture(path, url=None): with open(os.path.join(TEST_DIR, path)) as f: p = Parser(doc=f, url=url, html_parser='html5lib') return p.to_dict()
def test_simple_person_reference_implied(): p = Parser(doc=open("test/examples/simple_person_reference_implied.html")) result = p.to_dict() assert_equal(result["items"][0]["properties"], {'name': ['Frances Berriman']})
def test_open_file(): p = Parser(doc=open("test/examples/empty.html")) assert_true(p.__doc__ is not None) assert_true(type(p) is not None) assert_true(type(p.to_dict()) is dict)
def parse_fixture(path, url=None): with open(os.path.join("test/examples/", path)) as f: p = Parser(doc=f, url=url, html_parser='html5lib') return p.to_dict()
def test_simple_person_reference_implied(): p = Parser(doc=open("test/examples/simple_person_reference_implied.html")) result = p.to_dict() assert_equal(result["items"][0]["properties"], {'name': ['Frances Berriman']})
def test_open_file(): p = Parser(doc=open("test/examples/empty.html")) assert_true(p.__doc__ is not None) assert_true(type(p) is not None) assert_true(type(p.to_dict()) is dict)
def parse_fixture(path, url=None): with open(os.path.join("test/examples/", path)) as f: p = Parser(doc=f, url=url, html_parser='html5lib') return p.to_dict()