mirror of
https://github.com/wassname/segpy.git
synced 2026-06-27 19:00:53 +08:00
Test end-text stanza present in extended headers.
This commit is contained in:
@@ -8,53 +8,53 @@ from segpy.toolkit import format_extended_textual_header, CARDS_PER_HEADER, END_
|
||||
from segpy.portability import unicode
|
||||
|
||||
|
||||
# class MultiLineString(str):
|
||||
# pass
|
||||
#
|
||||
#
|
||||
# class MultiLineStringStrategy(MappedSearchStrategy):
|
||||
#
|
||||
# def pack(self, x):
|
||||
# return '\n'.join(x)
|
||||
#
|
||||
# def unpack(self, x):
|
||||
# return ''.join(x.splitlines())
|
||||
#
|
||||
#
|
||||
# StrategyTable.default().define_specification_for(
|
||||
# MultiLineString,
|
||||
# lambda s, d: MultiLineStringStrategy(
|
||||
# strategy=s.strategy([str]),
|
||||
# descriptor=MultiLineString))
|
||||
class MultiLineString(unicode):
|
||||
pass
|
||||
|
||||
|
||||
class MultiLineStringStrategy(MappedSearchStrategy):
|
||||
|
||||
def pack(self, x):
|
||||
return MultiLineString(unicode('\n').join(x))
|
||||
|
||||
def unpack(self, x):
|
||||
return x.splitlines()
|
||||
|
||||
|
||||
StrategyTable.default().define_specification_for(
|
||||
MultiLineString,
|
||||
lambda s, d: MultiLineStringStrategy(
|
||||
strategy=s.strategy([str]),
|
||||
descriptor=MultiLineString))
|
||||
|
||||
|
||||
class TestFormatExtendedTextualHeader(unittest.TestCase):
|
||||
|
||||
@given(unicode,
|
||||
@given(MultiLineString,
|
||||
sampled_from([ASCII, EBCDIC]),
|
||||
bool)
|
||||
def test_forty_lines_per_page(self, text, encoding, include_text_stop):
|
||||
pages = format_extended_textual_header(text, encoding, include_text_stop)
|
||||
self.assertTrue(all(len(page) == CARDS_PER_HEADER for page in pages))
|
||||
|
||||
@given(unicode,
|
||||
@given(MultiLineString,
|
||||
sampled_from([ASCII, EBCDIC]),
|
||||
bool)
|
||||
def test_eighty_bytes_per_encoded_line(self, text, encoding, include_text_stop):
|
||||
pages = format_extended_textual_header(text, encoding, include_text_stop)
|
||||
self.assertTrue(all([len(line.encode(encoding)) == CARD_LENGTH for page in pages for line in page]))
|
||||
|
||||
@given(unicode,
|
||||
@given(MultiLineString,
|
||||
sampled_from([ASCII, EBCDIC]),
|
||||
bool)
|
||||
def test_lines_end_with_cr_lf(self, text, encoding, include_text_stop):
|
||||
pages = format_extended_textual_header(text, encoding, include_text_stop)
|
||||
self.assertTrue(all([line.endswith('\r\n') for page in pages for line in page]))
|
||||
|
||||
@given(unicode,
|
||||
@given(MultiLineString,
|
||||
sampled_from([ASCII, EBCDIC]),
|
||||
just(True))
|
||||
def test_lines_end_with_cr_lf(self, text, encoding, include_text_stop):
|
||||
def test_end_text_stanza_present(self, text, encoding, include_text_stop):
|
||||
pages = format_extended_textual_header(text, encoding, include_text_stop)
|
||||
self.assertTrue(pages[-1][0].startswith(END_TEXT_STANZA))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user