Guide
Intro text.
Authentication
Use the token parse_float parameter.
Details
Deeper.
Limits
| k | v |
|---|---|
| a | 1 |
import pytest import json_reader from html_reader import render_html DOC = b"""
Intro text.
Use the token parse_float parameter.
Deeper.
| k | v |
|---|---|
| a | 1 |
x
", "https://e.com/", None, "outline", None, 2) assert "no headings" in outline.lower() def test_section_by_label_and_by_id(): _, by_label = render_html(DOC, "https://example.com/", None, "section", "Authentication", 2) assert "parse_float" in by_label _, by_id = render_html(DOC, "https://example.com/", None, "section", "@2", 2) assert "parse_float" in by_id def test_section_unknown_heading(): with pytest.raises(ValueError): render_html(DOC, "https://example.com/", None, "section", "nope", 2) def test_find_is_literal_and_case_insensitive(): _, found = render_html(DOC, "https://example.com/", None, "find", "PARSE_FLOAT", 1) assert "**@2" in found assert "parse" in found.replace("\\_", "_") def test_find_without_match_returns_message(): _, found = render_html(DOC, "https://example.com/", None, "find", "absent", 1) assert "No matches" in found def test_css_selects_and_absolutizes_links(): _, table = render_html(DOC, "https://example.com/a/b", None, "css", "table", 2) assert "| a | 1 |" in table _, link = render_html(DOC, "https://example.com/a/b", None, "css", "article p a", 2) assert "https://example.com/rel" in link def test_css_invalid_selector(): with pytest.raises(ValueError): render_html(DOC, "https://example.com/", None, "css", "[[", 2) def test_text_mode_renders_markdown(): _, text = render_html(DOC, "https://example.com/", None, "text", None, 2) assert "## Authentication" in text assert "| k | v |" in text def test_unknown_mode(): with pytest.raises(ValueError): render_html(DOC, "https://example.com/", None, "jsonpath", None, 2) DATA = { "info": {"name": "pkg", "tags": ["a", "b"]}, "urls": [{"filename": "x.whl"}, {"filename": "y.tar.gz"}], "none": None, } def test_shape_reports_types_without_values(): shape = json_reader.shape(DATA) assert shape["type"] == "object" assert shape["fields"]["info"]["fields"]["name"] == "string" assert shape["fields"]["urls"]["type"] == "array" def test_select_field_index_and_wildcard(): assert json_reader.select(DATA, "$.info.name") == "pkg" assert json_reader.select(DATA, "$.urls[1].filename") == "y.tar.gz" assert json_reader.select(DATA, "$.urls[*].filename") == ["x.whl", "y.tar.gz"] assert json_reader.select(DATA, '$["info"]["name"]') == "pkg" @pytest.mark.parametrize("path", ["info", "$.missing", "$.info.name.deeper", "$[9]"]) def test_select_errors(path): with pytest.raises(ValueError): json_reader.select(DATA, path) def test_render_json_modes(): body = b'{"a": 1}' assert json_reader.render_json(body, "outline", None).startswith('{"type"') assert json_reader.render_json(body, "jsonpath", "$.a") == "1" assert json_reader.render_json(body, "text", None) == '{"a":1}' with pytest.raises(ValueError): json_reader.render_json(body, "css", None)