<s> import unittest <EOL> from robot . reporting . jsexecutionresult import JsExecutionResult <EOL> from robot . reporting . jswriter import JsResultWriter <EOL> from robot . utils import StringIO <EOL> from robot . utils . asserts import assert_equal , assert_true <EOL> def get_lines ( suite = ( ) , strings = ( ) , basemillis = <NUM_LIT:100> , start_block = '<STR_LIT>' , <EOL> end_block = '<STR_LIT>' , split_threshold = <NUM_LIT> , min_level = '<STR_LIT>' ) : <EOL> output = StringIO ( ) <EOL> data = JsExecutionResult ( suite , None , None , strings , basemillis , min_level = min_level ) <EOL> writer = JsResultWriter ( output , start_block , end_block , split_threshold ) <EOL> writer . write ( data , settings = { } ) <EOL> return output . getvalue ( ) . splitlines ( ) <EOL> def assert_separators ( lines , separator , end_separator = False ) : <EOL> for index , line in enumerate ( lines ) : <EOL> if index % <NUM_LIT:2> == int ( end_separator ) : <EOL> assert_equal ( line , separator ) <EOL> else : <EOL> assert_true ( line . startswith ( '<STR_LIT>' ) , line ) <EOL> class TestDataModelWrite ( unittest . TestCase ) : <EOL> def test_writing_datamodel_elements ( self ) : <EOL> lines = get_lines ( min_level = '<STR_LIT>' ) <EOL> assert_true ( lines [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) , lines [ <NUM_LIT:0> ] ) <EOL> assert_true ( lines [ <NUM_LIT:1> ] . startswith ( '<STR_LIT>' ) , lines [ <NUM_LIT:1> ] ) <EOL> assert_true ( lines [ - <NUM_LIT:1> ] . startswith ( '<STR_LIT>' ) , lines [ - <NUM_LIT:1> ] ) <EOL> def test_writing_datamodel_with_separator ( self ) : <EOL> lines = get_lines ( start_block = '<STR_LIT>' ) <EOL> assert_true ( len ( lines ) >= <NUM_LIT:2> ) <EOL> assert_separators ( lines , '<STR_LIT>' ) <EOL> def test_splitting_output_strings ( self ) : <EOL> lines = get_lines ( strings = [ '<STR_LIT:data>' for _ in range ( <NUM_LIT:100> ) ] , <EOL> split_threshold = <NUM_LIT:9> , end_block = '<STR_LIT>' ) <EOL> parts = [ l for l in lines if l . startswith ( '<STR_LIT>' ) ] <EOL> assert_equal ( len ( parts ) , <NUM_LIT> ) <EOL> assert_equal ( parts [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> for line in parts [ <NUM_LIT:1> : ] : <EOL> assert_true ( line . startswith ( '<STR_LIT>' ) , line ) <EOL> assert_separators ( lines , '<STR_LIT:?>' , end_separator = True ) <EOL> class TestSuiteWriter ( unittest . TestCase ) : <EOL> def test_no_splitting ( self ) : <EOL> suite = ( <NUM_LIT:1> , ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:4> , ( <NUM_LIT:5> , ) , ( <NUM_LIT:6> , ( ) ) ) , <NUM_LIT:8> ) <EOL> expected = [ '<STR_LIT>' ] <EOL> self . _assert_splitting ( suite , <NUM_LIT:100> , expected ) <EOL> def test_simple_splitting_version_1 ( self ) : <EOL> suite = ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) , ( <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ) , <NUM_LIT:9> ) <EOL> expected = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . _assert_splitting ( suite , <NUM_LIT:4> , expected ) <EOL> def test_simple_splitting_version_2 ( self ) : <EOL> suite = ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) , ( <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ) , <NUM_LIT:9> , <NUM_LIT:10> ) <EOL> expected = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . _assert_splitting ( suite , <NUM_LIT:4> , expected ) <EOL> def test_simple_splitting_version_3 ( self ) : <EOL> suite = ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) , ( <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ) , <NUM_LIT:11> ) <EOL> expected = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . _assert_splitting ( suite , <NUM_LIT:4> , expected ) <EOL> def test_tuple_itself_has_size_one ( self ) : <EOL> suite = ( ( <NUM_LIT:1> , ( ) , ( ) , <NUM_LIT:4> ) , ( ( ( ( ( ) , ) , ) , ) , ) ) <EOL> expected = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . _assert_splitting ( suite , <NUM_LIT:4> , expected ) <EOL> def test_nested_splitting ( self ) : <EOL> suite = ( <NUM_LIT:1> , ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:4> , ( <NUM_LIT:5> , ) , ( <NUM_LIT:6> , <NUM_LIT:7> ) ) , <NUM_LIT:8> ) <EOL> expected = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . _assert_splitting ( suite , <NUM_LIT:2> , expected ) <EOL> def _assert_splitting ( self , suite , threshold , expected ) : <EOL> lines = get_lines ( suite , split_threshold = threshold , start_block = '<STR_LIT>' ) <EOL> parts = [ l for l in lines if l . startswith ( ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) ] <EOL> assert_equal ( parts , expected ) <EOL> assert_separators ( lines , '<STR_LIT:foo>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
