コード例 #1
0
ファイル: element.py プロジェクト: unkvuzutop/python-htmlgen
 def test_generate_with_children(self):
     element = Element("div")
     element.extend(["<foo>", "&"])
     element.append_raw("&lt;bar&gt;")
     assert_equal(
         [b"<div>", b"&lt;foo&gt;", b"&amp;", b"&lt;bar&gt;", b"</div>"],
         list(iter(element)))
コード例 #2
0
ファイル: document.py プロジェクト: srittau/python-htmlgen
 def test_scripts(self):
     head = _TestingHead()
     doc = Document()
     doc.root.head = head
     doc.add_script("script.js")
     doc.add_scripts("script1.js", "script2.js")
     assert_equal(["script.js", "script1.js", "script2.js"], head.scripts)
コード例 #3
0
ファイル: document.py プロジェクト: unkvuzutop/python-htmlgen
 def test_default_language(self):
     root = HTMLRoot()
     root.head = _TestingHead()
     assert_equal([b'<html lang="en" xml:lang="en" '
                   b'xmlns="http://www.w3.org/1999/xhtml">',
                   b'<body>', b'</body>', b'</html>'],
                  list(iter(root)))
コード例 #4
0
ファイル: document.py プロジェクト: srittau/python-htmlgen
 def test_append(self):
     doc = Document()
     old_child_count = len(doc.root.head)
     doc.append_head("Test Head")
     assert_equal(old_child_count + 1, len(doc.root.head))
     doc.append_body("Test Body")
     assert_equal(1, len(doc.root.body))
コード例 #5
0
ファイル: element.py プロジェクト: unkvuzutop/python-htmlgen
 def test_remove_attribute(self):
     element = Element("div")
     element.remove_attribute("foo")
     element.set_attribute("foo", "bar")
     element.remove_attribute("foo")
     assert_is_none(element.get_attribute("foo"))
     assert_equal([b'<div>', b"</div>"], list(iter(element)))
コード例 #6
0
ファイル: form.py プロジェクト: srittau/python-htmlgen
 def test_create_option__option_object(self):
     select = Select()
     option = select.create_option("Option Label", "test-value",
                                   selected=True)
     assert_equal("option", option.element_name)
     assert_equal("test-value", option.value)
     assert_true(option.selected)
コード例 #7
0
ファイル: table.py プロジェクト: unkvuzutop/python-htmlgen
 def test_create_column(self):
     group = ColumnGroup()
     col = group.create_column()
     col.add_css_classes("col-cls")
     group.create_column()
     assert_equal('<colgroup><col class=\"col-cls\"></col><col></col>'
                  '</colgroup>', str(group))
コード例 #8
0
ファイル: attribute.py プロジェクト: srittau/python-htmlgen
 def test_time_with_fraction(self):
     class MyElement(Element):
         attr = time_html_attribute("data-time")
     element = MyElement("div")
     element.attr = datetime.time(14, 13, 9, 123456)
     assert_equal(datetime.time(14, 13, 9, 123456), element.attr)
     assert_equal('<div data-time="14:13:09.123456"></div>', str(element))
コード例 #9
0
ファイル: form.py プロジェクト: srittau/python-htmlgen
 def test_attributes(self):
     number = NumberInput()
     number.minimum = 4.1
     number.maximum = 10.5
     number.step = 0.8
     assert_equal('<input max="10.5" min="4.1" step="0.8" type="number"/>',
                  str(number))
コード例 #10
0
ファイル: form.py プロジェクト: srittau/python-htmlgen
 def test_defaults(self):
     time = TimeInput()
     assert_equal("", time.name)
     assert_is_none(time.time)
     assert_is_none(time.minimum)
     assert_is_none(time.maximum)
     assert_is_none(time.step)
     assert_equal('<input type="time"/>', str(time))
コード例 #11
0
ファイル: element.py プロジェクト: unkvuzutop/python-htmlgen
 def test_generate_children(self):
     class TestingElement(NonVoidElement):
         def generate_children(self):
             yield "Hello World!"
             yield VoidElement("br")
     element = TestingElement("div")
     assert_equal([b"<div>", b"Hello World!", b"<br/>", b"</div>"],
                  list(iter(element)))
コード例 #12
0
ファイル: form.py プロジェクト: srittau/python-htmlgen
 def test_boolean_attributes(self):
     input_ = Input()
     input_.disabled = True
     input_.focus = True
     input_.readonly = True
     assert_equal([b'<input autofocus="autofocus" disabled="disabled" '
                   b'readonly="readonly" type="text"/>'],
                  list(iter(input_)))
コード例 #13
0
ファイル: form.py プロジェクト: srittau/python-htmlgen
 def test_attributes(self):
     input_ = Input()
     input_.placeholder = "Foo"
     input_.size = 5
     input_.value = "My Value"
     assert_equal([b'<input placeholder="Foo" size="5" type="text" '
                   b'value="My Value"/>'],
                  list(iter(input_)))
コード例 #14
0
ファイル: document.py プロジェクト: srittau/python-htmlgen
 def test_stylesheets(self):
     head = _TestingHead()
     doc = Document()
     doc.root.head = head
     doc.add_stylesheet("style.css")
     doc.add_stylesheets("style1.css", "style2.css")
     assert_equal(["style.css", "style1.css", "style2.css"],
                  head.stylesheets)
コード例 #15
0
ファイル: element.py プロジェクト: unkvuzutop/python-htmlgen
 def test_append_extend(self):
     element = Element("div")
     element.append("Hello")
     element.extend([", ", "World", "!"])
     assert_equal(4, len(element))
     element.append_raw("Hello")
     element.extend_raw([", ", "World", "!"])
     assert_equal(8, len(element))
コード例 #16
0
ファイル: document.py プロジェクト: unkvuzutop/python-htmlgen
 def test_append(self):
     head = _TestingHead()
     doc = Document()
     doc.root.head = head
     doc.append_head("Test Head")
     assert_equal(1, len(head))
     doc.append_body("Test Body")
     assert_equal(1, len(doc.root.body))
コード例 #17
0
ファイル: element.py プロジェクト: unkvuzutop/python-htmlgen
 def test_add_multiple_css_classes(self):
     element = Element("div")
     element.add_css_classes("foo", "bar", "baz")
     element.add_css_classes("bar")
     matches = re.search(r'class="(.*)"', str(element))
     css_classes = matches.group(1).split(" ")
     css_classes.sort()
     assert_equal(["bar", "baz", "foo"], css_classes)
コード例 #18
0
ファイル: attribute.py プロジェクト: srittau/python-htmlgen
 def test_data(self):
     class MyElement(Element):
         attr = data_attribute("attr")
     element = MyElement("div")
     assert_is_none(element.get_attribute("data-attr"))
     element.attr = "foo"
     assert_equal("foo", element.get_attribute("data-attr"))
     element.set_attribute("data-attr", "bar")
     assert_equal("bar", element.attr)
コード例 #19
0
ファイル: form.py プロジェクト: srittau/python-htmlgen
 def test_minimum_maximum(self):
     time = TimeInput()
     time.minimum = datetime.time(12, 14)
     time.maximum = datetime.time(19, 45)
     assert_equal('<input max="19:45:00" min="12:14:00" type="time"/>',
                  str(time))
     time.minimum = None
     time.maximum = None
     assert_equal('<input type="time"/>', str(time))
コード例 #20
0
ファイル: form.py プロジェクト: srittau/python-htmlgen
 def test_create_option__selected(self):
     select = Select()
     option = select.create_option("Option Label", "test-value",
                                   selected=True)
     assert_is(option, select.selected_option)
     assert_equal(
         '<select><option selected="selected" value="test-value">'
         'Option Label</option></select>',
         str(select))
コード例 #21
0
ファイル: document.py プロジェクト: srittau/python-htmlgen
 def test_custom_title_element(self):
     head = Head()
     old_title = head.title
     old_child_count = len(head)
     new_title = Title()
     head.title = new_title
     assert_equal(old_child_count, len(head))
     assert_is_not(old_title, head.title)
     assert_is(new_title, head.title)
コード例 #22
0
ファイル: form.py プロジェクト: srittau/python-htmlgen
 def test_set_selected_value(self):
     select = Select()
     select.create_option("L1", "v1")
     option = select.create_option("L2", "v2")
     select.create_option("L3", "v3")
     select.selected_value = "v2"
     assert_equal("v2", select.selected_value)
     assert_is(option, select.selected_option)
     assert_true(option.selected)
コード例 #23
0
ファイル: element.py プロジェクト: srittau/python-htmlgen
 def test_remove_css_classes(self):
     element = Element("div")
     element.add_css_classes("foo", "bar", "baz")
     element.remove_css_classes("bar", "xxx")
     matches = re.search(r'class="(.*)"', str(element))
     assert matches is not None
     css_classes = matches.group(1).split(" ")
     css_classes.sort()
     assert_equal(["baz", "foo"], css_classes)
コード例 #24
0
ファイル: table.py プロジェクト: unkvuzutop/python-htmlgen
 def test_children_order(self):
     table = Table()
     table.append_raw("<tr>Bare line</tr>")
     table.create_row()
     table.create_header_row()
     assert_equal([b"<table>",
                   b"<thead>", b"<tr>", b"</tr>", b"</thead>",
                   b"<tbody>", b"<tr>", b"</tr>", b"</tbody>",
                   b"<tr>Bare line</tr>",
                   b"</table>"], list(iter(table)))
コード例 #25
0
ファイル: list.py プロジェクト: srittau/python-htmlgen
 def test_create_items(self):
     list_ = UnorderedList()
     items = list_.create_items("foo", "bar", "baz")
     assert_equal([b"<ul>",
                   b"<li>", b"foo", b"</li>",
                   b"<li>", b"bar", b"</li>",
                   b"<li>", b"baz", b"</li>",
                   b"</ul>"],
                  list(iter(list_)))
     assert_equal(3, len(items))
コード例 #26
0
ファイル: element.py プロジェクト: unkvuzutop/python-htmlgen
 def test_set_multiple_styles(self):
     element = Element("div")
     element.set_style("color", "black")
     element.set_style("background-color", "rgb(255, 0, 0)")
     element.set_style("display", "block")
     matches = re.search(r'style="(.*)"', str(element))
     css_classes = matches.group(1).split("; ")
     css_classes.sort()
     assert_equal(["background-color: rgb(255, 0, 0)",
                   "color: black",
                   "display: block"], css_classes)
コード例 #27
0
ファイル: element.py プロジェクト: unkvuzutop/python-htmlgen
 def test_data_external(self):
     element = Element("div")
     element.set_attribute("data-foo", "bar")
     assert_equal("bar", element.data["foo"])
     element.data["xyz"] = "abc"
     assert_equal("abc", element.get_attribute("data-xyz"))
     element.data.clear()
     assert_is_none(element.get_attribute("data-foo"))
     element.set_attribute("data-old", "")
     element.data = {}
     assert_is_none(element.get_attribute("data-old"))
コード例 #28
0
ファイル: table.py プロジェクト: unkvuzutop/python-htmlgen
 def test_create_head_and_body(self):
     table = Table()
     table.create_body()
     table.create_head()
     table.create_row()
     table.create_header_row()
     assert_equal([b"<table>",
                   b"<thead>", b"<tr>", b"</tr>", b"</thead>",
                   b"<tbody>", b"<tr>", b"</tr>", b"</tbody>",
                   b"<tbody>", b"</tbody>",
                   b"<thead>", b"</thead>",
                   b"</table>"], list(iter(table)))
コード例 #29
0
ファイル: element.py プロジェクト: unkvuzutop/python-htmlgen
    def test_attribute_order(self):
        """Test attribute order.

        The attributes are ordered alphabetically so that unit and doctests
        can rely on this order.

        """
        element = Element("div")
        element.set_attribute("def", "")
        element.set_attribute("abc", "")
        element.set_attribute("ghi", "")
        assert_equal([b'<div abc="" def="" ghi="">', b"</div>"],
                     list(iter(element)))
コード例 #30
0
ファイル: document.py プロジェクト: srittau/python-htmlgen
 def test_title(self):
     doc = Document(title="Test Title")
     assert_equal("Test Title", doc.title)
     assert_equal("Test Title", doc.root.head.title.title)
     doc.title = "New Title"
     assert_equal("New Title", doc.title)
     assert_equal("New Title", doc.root.head.title.title)
コード例 #31
0
 def test_append_raw(self):
     generator = HTMLChildGenerator()
     generator.append_raw(u"c1&c2")
     generator.append_raw(_TestingGenerator([u"c3", u"<c4>"]))
     assert_equal([b"c1&c2", b"c3", b"<c4>"], list(iter(generator)))
コード例 #32
0
 def app(env: WSGIEnvironment, sr: StartResponse) -> Iterable[bytes]:
     assert_equal(expected_path, env["PATH_INFO"])
     sr("200 OK", [])
     return []
コード例 #33
0
 def test_children(self):
     generator = ChildGenerator()
     generator.append("Foo")
     assert_equal(["Foo"], generator.children)
     generator.children.append("Bar")
     assert_equal(["Foo"], generator.children)
コード例 #34
0
 def test_wrap_string(self):
     generator = generate_html_string("Test")
     assert_is_instance(generator, HTMLChildGenerator)
     result = list(iter(generator))
     assert_equal([b"Test"], result)
コード例 #35
0
 def handle_path(_: Request, paths: Sequence[Any], __: str) -> int:
     assert_equal(("xyz", ), paths)
     return 123
コード例 #36
0
 def test_len(self):
     generator = HTMLChildGenerator()
     generator.append(u"c1")
     generator.extend([u"c2", u"c3", NullGenerator()])
     assert_equal(4, len(generator))
コード例 #37
0
 def test_children(self):
     generator = HTMLChildGenerator()
     generator.append("Foo")
     generator.append("<tag>")
     assert_equal(["Foo", "&lt;tag&gt;"], generator.children)
コード例 #38
0
ファイル: changelog.py プロジェクト: hellmake/quality-time
def check_changelog(context, item=None):
    """Check that the changelog contains the text."""
    item_path = f"{item}/{context.uuid[item]}/" if item else ""
    response = context.get(f"changelog/{item_path}10")
    for index, line in enumerate(context.text.split("\n")):
        assert_equal(line, response["changelog"][index]["delta"])
コード例 #39
0
from asserts import assert_true, assert_equal
from unittest.mock import patch
from io import StringIO

with patch('sys.stdout', new=StringIO()) as fake_output:
    import index
    actual = fake_output.getvalue().strip()
    assert_equal(actual, 'What Is Dead May Never Die')

print(actual)
コード例 #40
0
 def sub(environ: WSGIEnvironment, sr: StartResponse) -> WSGIResponse:
     assert_equal("/sub", environ["PATH_INFO"])
     sr("204 No Content", [])
     return []
コード例 #41
0
ファイル: test.py プロジェクト: lex111/exercises-python
from asserts import assert_true, assert_equal
from unittest.mock import patch
from io import StringIO

with patch("sys.stdout", new=StringIO()) as fake_output:
    import index

    actual = fake_output.getvalue().strip()
    assert_equal(actual, "49.0")

print(actual)
コード例 #42
0
 def handle(environ: WSGIEnvironment,
            sr: StartResponse) -> Sequence[bytes]:
     assert_equal(expected_path, environ["PATH_INFO"])
     sr("200 OK", [])
     return []
コード例 #43
0
 def tmpl(_: Request, path: Sequence[str], v: str) -> str:
     assert_equal((), path)
     return v * 2
コード例 #44
0
 def handle(environ: WSGIEnvironment,
            start_response: StartResponse) -> Iterable[bytes]:
     assert_equal(["xyzxyz"], environ["rouver.path_args"])
     start_response("200 OK", [])
     return []
コード例 #45
0
 def test_extend_raw(self):
     generator = HTMLChildGenerator()
     generator.append(u"c1")
     generator.extend_raw([_TestingGenerator([u"c&2", u"c3"]), u"<c4>"])
     assert_equal([b"c1", b"c&2", b"c3", b"<c4>"], list(iter(generator)))
コード例 #46
0
def validate_price_dict(dict):
    assert_equal(_instrument, dict["instrument"])
    assert_equal(_status, dict["status"])
    assert_equal(__time, dict["time"])
    assert_equal(_tradeable, dict["tradeable"])
    assert_equal(_ask, dict["ask"])
    assert_equal(_mid, dict["mid"])
    assert_equal(_spread, dict["spread"])
    assert_equal(_ask_liquidity, dict["ask_liquidity"])
    assert_equal(_bid_liquidity, dict["bid_liquidity"])
    assert_equal(_ask_closeout, dict["ask_closeout"])
    assert_equal(_bid_closeout, dict["bid_closeout"])
コード例 #47
0
 def test_remove_raw(self):
     generator = HTMLChildGenerator()
     generator.extend_raw(["foo", "bar", "lower < than"])
     generator.remove_raw("foo")
     generator.remove_raw("lower < than")
     assert_equal([b"bar"], list(iter(generator)))
コード例 #48
0
 def handle(environ: WSGIEnvironment,
            start_response: StartResponse) -> Iterable[bytes]:
     assert_equal(["value"], environ["rouver.path_args"])
     assert_equal("/abc/def", environ["rouver.wildcard_path"])
     start_response("200 OK", [])
     return [b""]
コード例 #49
0
 def test_empty(self):
     generator = HTMLChildGenerator()
     generator.append(u"c1")
     generator.extend([u"c2", u"c3", NullGenerator()])
     generator.empty()
     assert_equal([], list(iter(generator)))
コード例 #50
0
 def handle_path(_: Request, __: Any, v: str) -> None:
     assert_equal("foo/bar", v)
コード例 #51
0
 def test_children_readonly(self):
     generator = HTMLChildGenerator()
     generator.append("Foo")
     generator.children.append("Bar")
     assert_equal(["Foo"], generator.children)
コード例 #52
0
 def handle_path(request: Request, paths: Sequence[Any],
                 path: str) -> str:
     assert_is_instance(request, Request)
     assert_equal((), paths)
     return path * 2
コード例 #53
0
 def test_escape_string(self):
     generator = generate_html_string("<br>")
     assert_is_instance(generator, HTMLChildGenerator)
     result = list(iter(generator))
     assert_equal([b"&lt;br&gt;"], result)
コード例 #54
0
def check_json_error(context):
    """Check the json error."""
    assert_equal(400, context.response.status_code)
    assert_equal("application/json", context.response.headers["Content-Type"])
コード例 #55
0
def validate_price(price: Price):
    assert_equal(_instrument, price.instrument)
    assert_equal(_status, price.status)
    assert_equal(__time, price.time)
    assert_equal(_tradeable, price.tradeable)
    assert_equal(_ask, price.ask)
    assert_equal(_mid, price.mid)
    assert_equal(_spread, price.spread)
    assert_equal(_ask_liquidity, price.ask_liquidity)
    assert_equal(_bid_liquidity, price.bid_liquidity)
    assert_equal(_ask_closeout, price.ask_closeout)
    assert_equal(_bid_closeout, price.bid_closeout)
コード例 #56
0
 def handle(environ: WSGIEnvironment,
            start_response: StartResponse) -> Iterable[bytes]:
     assert_equal("test.example.com", environ["SERVER_NAME"])
     start_response("200 OK", [])
     return [b""]
コード例 #57
0
ファイル: test.py プロジェクト: lex111/exercises-python
from asserts import assert_true, assert_equal
from unittest.mock import patch
from io import StringIO

with patch("sys.stdout", new=StringIO()) as fake_output:
    import index

    actual = fake_output.getvalue().strip()
    assert_equal(actual, "4")

print(actual)
コード例 #58
0
def check_pdf(context):
    """Check the pdf."""
    assert_equal("application/pdf", context.response.headers["Content-Type"])
コード例 #59
0
 def app(env: WSGIEnvironment, sr: StartResponse) -> Iterable[bytes]:
     assert_equal("/foo", env["PATH_INFO"])
     assert_equal("/sub/foo", env["rouver.original_path_info"])
     sr("200 OK", [])
     return []
コード例 #60
0
 def handle(environ: WSGIEnvironment,
            start_response: StartResponse) -> Iterable[bytes]:
     assert_equal("/", environ["rouver.wildcard_path"])
     start_response("200 OK", [])
     return []