def test_defaults(self): input_ = DateInput() assert_equal("date", input_.type) assert_equal("", input_.name) assert_is_none(input_.date) assert_equal("", input_.value) assert_equal('<input type="date"/>', str(input_))
def test_defaults(self): number = NumberInput() assert_equal("number", number.type) assert_equal("", number.name) assert_equal("", number.value) assert_is_none(number.number) assert_equal('<input type="number"/>', str(number))
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)))
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)
def test_step(self): time = TimeInput() time.step = 12.3 assert_equal(12.3, time.step) assert_equal('<input step="12.3" type="time"/>', str(time)) time.step = None assert_is_none(time.step) assert_equal('<input type="time"/>', str(time)) time.set_attribute("step", "any") assert_is_none(time.step)
def test_value(self): input_ = DateInput() input_.value = "2012-03-08" assert_equal(datetime.date(2012, 3, 8), input_.date) input_.value = "invalid" assert_is_none(input_.date) assert_equal('<input type="date" value="invalid"/>', str(input_)) input_.date = None assert_equal("", input_.value) assert_equal('<input type="date"/>', str(input_))
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"))
def test_id(self): element = Element("div") element.id = "Test-ID" assert_equal("Test-ID", element.id) assert_equal('<div id="Test-ID"></div>', str(element)) element.id = "" assert_is_none(element.id) assert_equal('<div></div>', str(element)) element.id = None assert_is_none(element.id) assert_equal('<div></div>', str(element))
def test_float(self): class MyElement(Element): attr = float_html_attribute("data-attr") element = MyElement("div") assert_is_none(element.attr) assert_equal("<div></div>", str(element)) element.attr = 4.2 assert_equal(4.2, element.attr) assert_equal('<div data-attr="4.2"></div>', str(element)) element.attr = None assert_is_none(element.attr) assert_equal('<div></div>', str(element))
def test_regular(self): class MyElement(Element): attr = html_attribute("data-attr") element = MyElement("div") assert_is_none(element.attr) assert_equal("<div></div>", str(element)) element.attr = "Foo" assert_equal("Foo", element.attr) assert_equal('<div data-attr="Foo"></div>', str(element)) element.attr = None assert_is_none(element.attr) assert_equal("<div></div>", str(element))
def test_time(self): class MyElement(Element): attr = time_html_attribute("data-time") element = MyElement("div") assert_is_none(element.attr) assert_equal("<div></div>", str(element)) element.attr = datetime.time(14, 13, 9) assert_equal(datetime.time(14, 13, 9), element.attr) assert_equal('<div data-time="14:13:09"></div>', str(element)) element.attr = None assert_is_none(element.attr) assert_equal('<div></div>', str(element)) element.set_attribute("data-time", "09:33:04") assert_equal(datetime.time(9, 33, 4), element.attr)
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))
def test_step_get_invalid(self): time = TimeInput() time.set_attribute("step", "invalid") assert_is_none(time.step) time.set_attribute("step", "0") assert_is_none(time.step) time.set_attribute("step", "-1") assert_is_none(time.step)
def assertIsNone(res): try: asserts.assert_is_none(res) except Exception as e: logger.error(e)
def test_get_selected_value__no_selected(self): select = Select() select.create_option("L1", "v1") assert_is_none(select.selected_value)
def test_get_selected_option__option_group_has_string_child(self): select = Select() group = select.create_group("") group.append("XXX") assert_is_none(select.selected_option)
def test_get_selected_option__non_option_elements(self): select = Select() select.append("String Content") assert_is_none(select.selected_option)
def test_data_with_default(self): class MyElement(Element): attr = data_attribute("attr", "def") element = MyElement("div") element.attr = "def" assert_is_none(element.get_attribute("data-attr"))
def test_url(self): script = Script(url="script.js") assert_equal("script.js", script.url) assert_is_none(script.script) assert_equal([b'<script src="script.js">', b'</script>'], list(iter(script)))
def test_defaults(self): file_input = FileInput() assert_equal("", file_input.name) assert_is_none(file_input.max_length) assert_equal('<input type="file"/>', str(file_input))
def test_for(self): label = Label() assert_is_none(label.for_) label.for_ = "my-id" assert_equal("my-id", label.for_) assert_equal('<label for="my-id"></label>', str(label))
def test_url(self): script = Script(url="script.js") assert_equal("script.js", script.url) assert_is_none(script.script) assert_equal([b'<script src="script.js">', b"</script>"], list(iter(script)))
def test_script(self): script = Script(script='alert("foo");') assert_is_none(script.url) assert_equal('alert("foo");', script.script) assert_equal([b"<script>", b'alert("foo");', b"</script>"], list(iter(script)))
def test_time__invalid_value(self): class MyElement(Element): attr = time_html_attribute("data-time") element = MyElement("div") element.set_attribute("data-time", "INVALID") assert_is_none(element.attr)
def test_get_selected_option__no_selected_elements(self): select = Select() select.create_option("L1", "v1") select.create_option("L2", "v2") select.create_option("L3", "v3") assert_is_none(select.selected_option)
def test_get_attribute(self): element = Element("div") assert_is_none(element.get_attribute("foo")) assert_equal("XXX", element.get_attribute("foo", default="XXX"))
def test_script(self): script = Script(script='alert("foo");') assert_is_none(script.url) assert_equal('alert("foo");', script.script) assert_equal([b'<script>', b'alert("foo");', b'</script>'], list(iter(script)))