<s> import unittest <EOL> from robot . utils . asserts import assert_true , assert_equal <EOL> from test_jsmodelbuilders import remap <EOL> from robot . reporting . jsexecutionresult import ( JsExecutionResult , <EOL> _KeywordRemover , StringIndex ) <EOL> from robot . reporting . jsmodelbuilders import SuiteBuilder , JsBuildingContext <EOL> from robot . result import TestSuite <EOL> class TestRemoveDataNotNeededInReport ( unittest . TestCase ) : <EOL> def test_remove_keywords ( self ) : <EOL> model = self . _create_suite_model ( ) <EOL> expected = self . _get_expected_suite_model ( model ) <EOL> result = _KeywordRemover ( ) . remove_keywords ( model ) <EOL> assert_equal ( result , expected ) <EOL> self . _verify_model_contains_no_keywords ( result ) <EOL> def _create_suite_model ( self ) : <EOL> self . context = JsBuildingContext ( ) <EOL> return SuiteBuilder ( self . context ) . build ( self . _get_suite ( ) ) <EOL> def _get_suite ( self ) : <EOL> suite = TestSuite ( name = '<STR_LIT:root>' , doc = '<STR_LIT>' , metadata = { '<STR_LIT:m>' : '<STR_LIT:v>' } ) <EOL> suite . keywords . create ( kwname = '<STR_LIT>' ) <EOL> sub = suite . suites . create ( name = '<STR_LIT>' , metadata = { '<STR_LIT:a>' : '<STR_LIT:1>' , '<STR_LIT:b>' : '<STR_LIT:2>' } ) <EOL> sub . keywords . create ( kwname = '<STR_LIT>' ) <EOL> t1 = sub . tests . create ( name = '<STR_LIT:test>' , tags = [ '<STR_LIT>' ] ) <EOL> t1 . keywords . create ( kwname = '<STR_LIT>' ) <EOL> t1 . keywords . create ( kwname = '<STR_LIT>' ) <EOL> t2 = sub . tests . create ( name = '<STR_LIT:test>' , tags = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> t2 . keywords . create ( kwname = '<STR_LIT>' ) <EOL> return suite <EOL> def _get_expected_suite_model ( self , suite ) : <EOL> suite = list ( suite ) <EOL> suite [ - <NUM_LIT:4> ] = tuple ( self . _get_expected_suite_model ( s ) for s in suite [ - <NUM_LIT:4> ] ) <EOL> suite [ - <NUM_LIT:3> ] = tuple ( self . _get_expected_test_model ( t ) for t in suite [ - <NUM_LIT:3> ] ) <EOL> suite [ - <NUM_LIT:2> ] = ( ) <EOL> return tuple ( suite ) <EOL> def _get_expected_test_model ( self , test ) : <EOL> test = list ( test ) <EOL> test [ - <NUM_LIT:1> ] = ( ) <EOL> return tuple ( test ) <EOL> def _verify_model_contains_no_keywords ( self , model , mapped = False ) : <EOL> if not mapped : <EOL> model = remap ( model , self . context . strings ) <EOL> assert_true ( '<STR_LIT>' not in model , '<STR_LIT>' ) <EOL> for item in model : <EOL> if isinstance ( item , tuple ) : <EOL> self . _verify_model_contains_no_keywords ( item , mapped = True ) <EOL> def test_remove_unused_strings ( self ) : <EOL> strings = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> model = ( <NUM_LIT:1> , StringIndex ( <NUM_LIT:0> ) , <NUM_LIT> , StringIndex ( <NUM_LIT:2> ) , - <NUM_LIT:1> , None ) <EOL> model , strings = _KeywordRemover ( ) . remove_unused_strings ( model , strings ) <EOL> assert_equal ( strings , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_equal ( model , ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> , - <NUM_LIT:1> , None ) ) <EOL> def test_remove_unused_strings_nested ( self ) : <EOL> strings = tuple ( '<STR_LIT>' ) <EOL> model = ( StringIndex ( <NUM_LIT:0> ) , StringIndex ( <NUM_LIT:1> ) , <NUM_LIT:2> , <NUM_LIT:3> , StringIndex ( <NUM_LIT:4> ) , <NUM_LIT:5> , <EOL> ( <NUM_LIT:0> , StringIndex ( <NUM_LIT:1> ) , <NUM_LIT:2> , StringIndex ( <NUM_LIT:3> ) , <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> model , strings = _KeywordRemover ( ) . remove_unused_strings ( model , strings ) <EOL> assert_equal ( strings , tuple ( '<STR_LIT>' ) ) <EOL> assert_equal ( model , ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:5> , ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:5> ) ) ) <EOL> def test_through_jsexecutionresult ( self ) : <EOL> suite = ( <NUM_LIT:0> , StringIndex ( <NUM_LIT:1> ) , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , StringIndex ( <NUM_LIT:5> ) , <EOL> ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , StringIndex ( <NUM_LIT:3> ) , <NUM_LIT:4> , <NUM_LIT:5> , ( ) , ( ) , ( '<STR_LIT>' , '<STR_LIT>' ) , <NUM_LIT:9> ) , ) , <EOL> ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , StringIndex ( <NUM_LIT:3> ) , <NUM_LIT:4> , <NUM_LIT:5> , ( '<STR_LIT:test>' , '<STR_LIT>' ) ) , <EOL> ( <NUM_LIT:0> , StringIndex ( <NUM_LIT:1> ) , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , ( '<STR_LIT:test>' , '<STR_LIT>' ) ) ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <NUM_LIT:9> ) <EOL> exp_s = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:2> , <EOL> ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , ( ) , ( ) , ( ) , <NUM_LIT:9> ) , ) , <EOL> ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , ( ) ) , <EOL> ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , ( ) ) ) , <EOL> ( ) , <NUM_LIT:9> ) <EOL> result = JsExecutionResult ( suite = suite , strings = tuple ( '<STR_LIT>' ) , <EOL> errors = ( <NUM_LIT:1> , <NUM_LIT:2> ) , statistics = { } , basemillis = <NUM_LIT:0> , <EOL> min_level = '<STR_LIT>' ) <EOL> assert_equal ( result . data [ '<STR_LIT>' ] , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> result . remove_data_not_needed_in_report ( ) <EOL> assert_equal ( result . strings , tuple ( '<STR_LIT>' ) ) <EOL> assert_equal ( result . suite , exp_s ) <EOL> assert_equal ( result . min_level , '<STR_LIT>' ) <EOL> assert_true ( '<STR_LIT>' not in result . data ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
