예제 #1
0
def test_join_should_fill_the_blanks_with_elements_received():
    template = Templater()
    template.learn('a b d')
    template.learn('a e d')
    parsed = template.parse('a b c d')
    result = template.join(parsed)
    expected = 'a b c d'
    assert result == expected
예제 #2
0
def test_join_should_fill_the_blanks_with_elements_received():
    template = Templater()
    template.learn('a b d')
    template.learn('a e d')
    parsed = template.parse('a b c d')
    result = template.join(parsed)
    expected = 'a b c d'
    assert result == expected
예제 #3
0
def test_save_should_use_NAMED_MARKER_if_template_has_named_markers_and_no_marker_supplied():
    t = Templater(template='{{one}}<u>{{two}}</u>{{three}}',
                  marker=regexp_marker)
    t.save('test.html')
    result = read_file_and_delete('test.html')
    named_markers = [NAMED_MARKER.format(header) for header in t._headers]
    expected = t.join(named_markers) + '\n'
    assert expected == result
예제 #4
0
def test_join_with_less_parameters_than_variables_should_raise_AttributeError():
    template = Templater()
    template.learn('a b d')
    template.learn('a e d')
    try:
        result = template.join([''])
    except AttributeError:
        pass
    else:
        assert 'AttributeError not raised!' == False
예제 #5
0
def test_save_should_use_headers_instead_of_self_headers_if_supplied():
    t = Templater(template='{{one}}<u>{{two}}</u>{{three}}',
                  marker=regexp_marker)
    t.save('test.html', headers=list('abc'))
    result_1 = read_file_and_delete('test.html')
    named_markers = [NAMED_MARKER.format(header) for header in list('abc')]
    expected_1 = t.join(named_markers) + '\n'
    assert expected_1 == result_1

    t.save('test.html', marker='[--{}--]', headers=list('abc'))
    result_2 = read_file_and_delete('test.html')
    expected_2 = '[--a--]<u>[--b--]</u>[--c--]' + '\n'
    assert expected_2 == result_2
예제 #6
0
def test_save_should_use_headers_instead_of_self_headers_if_supplied():
    t = Templater(template='{{one}}<u>{{two}}</u>{{three}}',
                  marker=regexp_marker)
    t.save('test.html', headers=list('abc'))
    result_1 = read_file_and_delete('test.html')
    named_markers = [NAMED_MARKER.format(header) for header in list('abc')]
    expected_1 = t.join(named_markers) + '\n'
    assert expected_1 == result_1

    t.save('test.html', marker='[--{}--]', headers=list('abc'))
    result_2 = read_file_and_delete('test.html')
    expected_2 = '[--a--]<u>[--b--]</u>[--c--]' + '\n'
    assert expected_2 == result_2
예제 #7
0
#!/usr/bin/env python
# coding: utf-8

from templater import Templater

template = Templater(template='<b>||| and |||</b>', marker='|||')
print template.join(['', 'red', 'blue', ''])  # prints '<b>red and blue</b>'
예제 #8
0
#!/usr/bin/env python
# coding: utf-8

from templater import Templater

template = Templater(template=[None, '<b>', None, '</b>', None])
print template.join(['', 'Python rules', '']) # prints '<b>Python rules</b>'
예제 #9
0
#!/usr/bin/env python
# coding: utf-8

from templater import Templater

texts_to_learn = [
    '<b> spam and eggs </b>', '<b> ham and spam </b>',
    '<b> white and black </b>'
]
text_to_parse = texts_to_learn[-1]
template = Templater()
for text in texts_to_learn:
    print('Learning "%s"...' % text)
    template.learn(text)
print('Template created:', template._template)
print('Parsing text "%s"...' % text_to_parse)
print('  Result:', template.parse(text_to_parse))
print('Filling the blanks:', template.join(['', 'yellow', 'blue', '']))
예제 #10
0
#!/usr/bin/env python
# coding: utf-8

from templater import Templater

template = Templater(template=[None, '<b>', None, '</b>', None])
print template.join(['', 'Python rules', ''])  # prints '<b>Python rules</b>'
예제 #11
0
def test_Templater_should_optionally_import_template_as_string_with_marks():
    template = Templater(template='<b>|||</b>', marker='|||')
    result_template = template._template
    assert result_template == [None, '<b>', None, '</b>', None]
    assert template.join(['', 'spam eggs', '']) == '<b>spam eggs</b>'
예제 #12
0
def test_Templater_should_optionally_import_pre_processed_template():
    pre_processed = [None, '<u>', None, '</u>', None]
    template = Templater(template=pre_processed)
    assert template._template == pre_processed
    assert template.join(['', 'python', '']) == '<u>python</u>'
예제 #13
0
def test_Templater_should_optionally_import_template_as_string_with_marks():
    template = Templater(template='<b>|||</b>', marker='|||')
    result_template = template._template
    assert result_template == [None, '<b>', None, '</b>', None]
    assert template.join(['', 'spam eggs', '']) == '<b>spam eggs</b>'
예제 #14
0
def test_Templater_should_optionally_import_pre_processed_template():
    pre_processed = [None, '<u>', None, '</u>', None]
    template = Templater(template=pre_processed)
    assert template._template == pre_processed
    assert template.join(['', 'python', '']) == '<u>python</u>'
#!/usr/bin/env python
# coding: utf-8

from templater import Templater


template = Templater(template='<b>||| and |||</b>', marker='|||')
print template.join(['', 'red', 'blue', '']) # prints '<b>red and blue</b>'
예제 #16
0
#!/usr/bin/env python
# coding: utf-8

from templater import Templater


texts_to_learn = ['<b> spam and eggs </b>', '<b> ham and spam </b>',
                  '<b> white and black </b>']
text_to_parse = texts_to_learn[-1]
template = Templater()
for text in texts_to_learn:
    print 'Learning "%s"...' % text
    template.learn(text)
print 'Template created:', template._template
print 'Parsing text "%s"...' % text_to_parse
print '  Result:', template.parse(text_to_parse)
print 'Filling the blanks:', template.join(['', 'yellow', 'blue', ''])