def test_validator_with_is_valid_with_invalid_schema(): exception_message = "" exception_raised = False try: is_valid(invalid_schema, { "name": "Daniel", "age": 30, "hired_at": "1970-01-01" }) except ValueError as value_error: exception_raised = True exception_message = str(value_error) assert exception_raised == True assert exception_message == "'sting' is not valid under any of the given schemas"
def test_special_chars(): str5 = "<p>4 \< 5</p>" assert is_valid(str5) == True str6 = "<p>1\<2</p>" assert is_valid(str6) == True str7 = "<p>\<not a tag\></p>" assert is_valid(str7) == True str8 = "<p>\\\<\></p>" assert is_valid(str8) == True str9 = "<p><not a tag></p>" assert is_valid(str9) == False
def test_validator_with_is_valid_missing_required_with_file(): absolute_path = os.path.dirname(os.path.abspath(__file__)) schema_file = os.path.join(absolute_path, "schemas/test-schema.json") validation = is_valid(schema_file, {"age": 30, "hired_at": "1970-01-01"}) print(validation) assert validation == False
def test_validator_with_is_valid(): validation = is_valid(test_schema, { "name": "Daniel", "age": 30, "hired_at": "1970-01-01", }) print(validation) assert validation == True
def test_validator_with_is_valid_wrong_format(): validation = is_valid(test_schema, { "name": "Daniel", "age": 30, "hired_at": "last year", }) print(validation) assert validation == False
def test_validator_simple_1(): """ test_validator_simple_1() Verify that we pass the simple use cases. """ input_string = 'aa bb cc dd ee' expected = True result = validator.is_valid(input_string) assert expected == result
def test_validator_simple_4(): """ test_validator_simple_4() Verify that we pass the simple use cases. """ input_string = 'aa aa cc dd' expected = False result = validator.is_valid(input_string) assert expected == result
def test_validator_with_is_valid_with_non_existing_file(): absolute_path = os.path.dirname(os.path.abspath(__file__)) schema_file = os.path.join(absolute_path, "schemas/does-not-exist.json") exception_message = "" exception_raised = False try: is_valid(schema_file, { "name": "Daniel", "age": 30, "hired_at": "1970-01-01" }) except FileNotFoundError as file_not_found: exception_raised = True exception_message = str(file_not_found)[-34:] assert exception_raised == True assert exception_message == "does-not-exist.json does not exist"
def test_full_doc(): str7 = """ <html> <head><title>Here's the title</title></head> <body> <p>Here's some stuff in the body</p> </body> </html> """ assert is_valid(str7) == True
def test_tag_is_invalid(): assert is_valid("<nor is this></nor is this>") == False assert is_valid("<<p>bad tag</p>") == False assert is_valid("<p*>no specials chars</p*>") == False assert is_valid("<>empty tag</>") == False assert is_valid("< >another empty tag</ >") == False assert is_valid("<p>this ends with a slash</") == False assert is_valid("<") == False assert is_valid("</") == False assert is_valid("/") == False assert is_valid("</closing_tag>") == False
def main(): while True: expression = input('Enter an expression (q - quit): ') if expression == 'q': break valid, tokens = is_valid(expression) if valid: print(evaluate(infix_to_postfix(tokens))) else: print('Invalid expression, try again.')
def canonicalize(url): if not is_valid(url): return None parsed = urlparse(url) scheme = _canon_scheme(parsed.scheme) netloc = _canon_netloc(parsed.netloc) path = _canon_path(parsed.path) params = _canon_params(parsed.params) query = _canon_query(parsed.query) fragment = _canon_fragment(parsed.fragment) return urlunparse((scheme, netloc, path, params, query, fragment))
def test_no_tags(): assert is_valid("not valid") == False assert is_valid("This <is> not </is> valid") == False
def test_null_or_empty_input(): assert is_valid("") == False assert is_valid(None) == False assert is_valid(" ") == False
def test_bad_nesting(): str4 = "<head><title>this is bad</head></title>" assert is_valid(str4) == False
def test_several_tags(): str3 = "<table><tr><td>item</td></tr></table>" assert is_valid(str3) == True
def test_tag_with_underscore(): assert is_valid("<tag_with_underscore></tag_with_underscore>") == True
def test_single_tag(): assert is_valid("<tag>this is valid</tag>") == True