<commit_before>#!/usr/bin/env python3

'''
Test code for html_render.py

'''

import io

from html_render import Element

def test_init():
    e = Element()
    
    e = Element('this is some text')
    
def test_content():
    # fixme: this tests internals!!!!
    e = Element('this is some text')
    
    assert 'this is some text' in e.content
    
def test_append():
    e = Element('this is some text')
    
    e.append('some more text')
    
    assert 'some more text' in e.content
    
def test_two_instances():
    e = Element('this is some text')
    e2 = Element('this is some other text')

    e.append('some more text')
    
    assert 'some more text' not in e2.content

def test_render():
    outfile = io.StringIO()
    e = Element('this is some text')
    e.append('some more text')
    e.render(outfile)
    
    outfile.seek(0)
    file_contents = outfile.read()
    
    assert('this is some text') in file_contents
    assert('some more text') in file_contents
    
    assert file_contents.startswith('<html>')
    assert file_contents.strip().endswith('<\html>')<commit_msg>WIP: Unit testing for html_render.py<commit_after>#!/usr/bin/env python3

'''
Test code for html_render.py

'''

import io

from html_render import Element, Html, Body, P

def test_init():
    e = Element()
    
    e = Element('this is some text')
    
def test_content():
    # fixme: this tests internals!!!!
    e = Element('this is some text')
    
    assert 'this is some text' in e.content
    
def test_append():
    e = Element('this is some text')
    
    e.append('some more text')

    assert 'some more text' in e.content
    
def test_two_instances():
    e = Element('this is some text')
    e2 = Element('this is some other text')

    e.append('some more text')
    
    assert 'some more text' not in e2.content

def test_render():
    outfile = io.StringIO()
    e = Element('this is some text')
    e.append('some more text')
    e.render(outfile)
    
    outfile.seek(0)
    file_contents = outfile.read()
    
    assert('this is some text') in file_contents
    assert('some more text') in file_contents
    
    assert file_contents.startswith('<html>')
    assert file_contents.strip().endswith('</html>')

# test Html, Body, P
{'fraction_non_alphanumeric': 0.12156166814551908, 'fraction_numerical': 0.00354924578527063, 'mean_word_length': 2.8415672913117547, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6952226', 'n_tokens_mistral': 731, 'n_tokens_neox': 723, 'n_words': 228}