예제 #1
0
class TestCTSRelease(PatcherTestCase, ConsoleOutputTestCase):

    def setUp(self):
        ConsoleOutputTestCase.setUp(self)
        self.patch_console(console=self.console)

        self.connection = Connection()

    def test_release_invalid_request_type(self):
        with self.assertRaises(SAPCliError) as cm:
            sap.cli.cts.release(None, SimpleNamespace(type='foo', number='WHATEVER', recursive=False))

        self.assertEqual(str(cm.exception), 'Internal error: unknown request type: foo')

    def release(self, **kwargs):
        sap.cli.cts.release(self.connection, SimpleNamespace(**kwargs))

    def do_check_command_release(self, request_type, number, response):
        self.connection.set_responses(
            Response(response, 200, {})
        )

        self.release(type=request_type, number=number, recursive=False)

        self.assertEqual(
            [request.adt_uri for request in self.connection.execs],
            [f'/sap/bc/adt/cts/transportrequests/{number}/newreleasejobs']
        )

        self.assertConsoleContents(self.console, stdout=f'''Releasing {number}
Transport request/task {number} was successfully released
''')

    def test_release_transport(self):
        self.do_check_command_release('transport', TRANSPORT_NUMBER, TRASNPORT_RELEASE_OK_RESPONSE)

    def test_release_task(self):
        self.do_check_command_release('task', TASK_NUMBER, TASK_RELEASE_OK_RESPONSE)

    @patch('sap.adt.cts.AbstractWorkbenchRequest.fetch')
    def test_recursive_release(self, fake_fetch):
        self.connection.set_responses(
            Response(TRASNPORT_RELEASE_OK_RESPONSE, 200, {})
        )

        self.release(type='transport', number=TRANSPORT_NUMBER, recursive=True)
        self.assertConsoleContents(self.console, stdout=f'''Fetching details of {TRANSPORT_NUMBER} because of recursive execution
Releasing {TRANSPORT_NUMBER}
Transport request/task {TRANSPORT_NUMBER} was successfully released
''')
        fake_fetch.assert_called_once()
예제 #2
0
class TestAUnitWrite(unittest.TestCase):

    def setUp(self):
        self.connection = Connection()

    def assert_print_no_test_classes(self, mock_print):
        self.assertEqual(
            mock_print.call_args_list[0],
            call('* [tolerable] [noTestClasses] - The task definition does not refer to any test', file=sys.stdout))

        self.assertEqual(
            mock_print.call_args_list[1],
            call('Successful: 0', file=sys.stdout))

        self.assertEqual(
            mock_print.call_args_list[2],
            call('Warnings:   0', file=sys.stdout))

        self.assertEqual(
            mock_print.call_args_list[3],
            call('Errors:     0', file=sys.stdout))

    def test_aunit_invalid(self):
        with self.assertRaises(SAPCliError) as cm:
            sap.cli.aunit.run('wrongconn', SimpleNamespace(type='foo', output='human'))

        self.assertEqual(str(cm.exception), 'Unknown type: foo')

    def test_print_aunit_output_raises(self):
        with self.assertRaises(SAPCliError) as cm:
            sap.cli.aunit.print_aunit_output(SimpleNamespace(output='foo'), Mock(), Mock())

        self.assertEqual(str(cm.exception), 'Unsupported output type: foo')

    def execute_run(self, *args, **kwargs):
        cmd_args = parse_args('run', *args, **kwargs)
        return cmd_args.execute(self.connection, cmd_args)

    def test_aunit_program(self):
        self.connection.set_responses(
            Response(status_code=200, text=AUNIT_NO_TEST_RESULTS_XML, headers={})
        )

        with patch('sap.cli.aunit.print') as mock_print:
            self.execute_run('program', '--output', 'human', 'yprogram', '--result', ResultOptions.ONLY_UNIT.value)

        self.assertEqual(len(self.connection.execs), 1)
        self.assertIn('programs/programs/yprogram', self.connection.execs[0].body)
        self.assert_print_no_test_classes(mock_print)

    def test_aunit_class_human(self):
        self.connection.set_responses(Response(status_code=200, text=AUNIT_NO_TEST_RESULTS_XML, headers={}))

        with patch('sap.cli.aunit.print') as mock_print:
            self.execute_run('class', 'yclass', '--output', 'human', '--result', ResultOptions.ONLY_UNIT.value)

        self.assertEqual(len(self.connection.execs), 1)
        self.assertIn('oo/classes/yclass', self.connection.execs[0].body)
        self.assert_print_no_test_classes(mock_print)

    def test_aunit_package(self):
        self.connection.set_responses(Response(status_code=200, text=AUNIT_NO_TEST_RESULTS_XML, headers={}))

        with patch('sap.cli.aunit.print') as mock_print:
            self.execute_run('package', 'ypackage', '--output', 'human', '--result', ResultOptions.ONLY_UNIT.value)

        self.assertEqual(len(self.connection.execs), 1)
        self.assertIn('packages/ypackage', self.connection.execs[0].body)
        self.assert_print_no_test_classes(mock_print)

    def test_aunit_junit4_no_test_methods(self):
        self.connection.set_responses(Response(status_code=200, text=AUNIT_RESULTS_NO_TEST_METHODS_XML, headers={}))

        with patch('sys.stdout', new_callable=StringIO) as mock_stdout:
            self.execute_run('package', 'ypackage', '--output', 'junit4', '--result', ResultOptions.ONLY_UNIT.value)

        self.assertEqual(len(self.connection.execs), 1)
        self.assertEqual(
            """<?xml version="1.0" encoding="UTF-8" ?>
<testsuites name="ypackage">
  <testsuite name="LTCL_TEST" package="ZCL_THEKING_MANUAL_HARDCORE" tests="0"/>
</testsuites>
""",
            mock_stdout.getvalue()
        )

    def test_aunit_package_with_results(self):
        self.connection.set_responses(Response(status_code=200, text=AUNIT_RESULTS_XML, headers={}))

        with patch('sap.cli.aunit.print') as mock_print:
            exit_code = self.execute_run('package', 'ypackage', '--output', 'human', '--result', ResultOptions.ONLY_UNIT.value)

        self.assertEqual(exit_code, 3)
        self.assertEqual(len(self.connection.execs), 1)
        self.assertIn('packages/ypackage', self.connection.execs[0].body)

        self.assertEqual(mock_print.call_args_list[0], call('ZCL_THEKING_MANUAL_HARDCORE', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[1], call('  LTCL_TEST', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[2], call('    DO_THE_FAIL [ERR]', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[3], call('    DO_THE_WARN [SKIP]', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[4], call('    DO_THE_TEST [OK]', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[5], call('  LTCL_TEST_HARDER', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[6], call('    DO_THE_FAIL [ERR]', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[7], call('    DO_THE_TEST [OK]', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[8], call('ZEXAMPLE_TESTS', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[9], call('  LTCL_TEST', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[10], call('    DO_THE_FAIL [ERR]', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[11], call('    DO_THE_TEST [OK]', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[12], call('', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[13], call('ZCL_THEKING_MANUAL_HARDCORE=>LTCL_TEST=>DO_THE_FAIL', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[14], call('*  [critical] [failedAssertion] - Critical Assertion Error: \'I am supposed to fail\'', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[15], call('ZCL_THEKING_MANUAL_HARDCORE=>LTCL_TEST_HARDER=>DO_THE_FAIL', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[16], call('*  [critical] [failedAssertion] - Critical Assertion Error: \'I am supposed to fail\'', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[17], call('ZEXAMPLE_TESTS=>LTCL_TEST=>DO_THE_FAIL', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[18], call('*  [critical] [failedAssertion] - Critical Assertion Error: \'I am supposed to fail\'', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[19], call('*  [critical] [failedAssertion] - Error<LOAD_PROGRAM_CLASS_MISMATCH>', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[20], call('', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[21], call('Successful: 3', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[22], call('Warnings:   1', file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[23], call('Errors:     3', file=sys.stdout))

    def test_aunit_package_with_results_raw(self):
        self.connection.set_responses(Response(status_code=200, text=AUNIT_RESULTS_XML, headers={}))

        with patch('sap.cli.aunit.print') as mock_print:
            exit_code = self.execute_run('package', 'ypackage', '--output', 'raw', '--result', ResultOptions.ONLY_UNIT.value)

        self.assertEqual(exit_code, 3)
        self.assertEqual(len(self.connection.execs), 1)
        self.assertIn('packages/ypackage', self.connection.execs[0].body)

        self.assertEqual(mock_print.call_args_list[0][0], (AUNIT_RESULTS_XML,))

    def test_aunit_package_with_results_junit4(self):
        self.connection.set_responses(Response(status_code=200, text=AUNIT_RESULTS_XML, headers={}))

        with patch('sys.stdout', new_callable=StringIO) as mock_stdout:
            exit_code = self.execute_run('package', 'ypackage', '--output', 'junit4', '--result', ResultOptions.ONLY_UNIT.value)

        self.assertEqual(exit_code, 3)
        self.assertEqual(len(self.connection.execs), 1)
        self.assertIn('packages/ypackage', self.connection.execs[0].body)

        self.maxDiff = None
        self.assertEqual(mock_stdout.getvalue(),
'''<?xml version="1.0" encoding="UTF-8" ?>
<testsuites name="ypackage">
  <testsuite name="LTCL_TEST" package="ZCL_THEKING_MANUAL_HARDCORE" tests="3">
    <testcase name="DO_THE_FAIL" classname="ZCL_THEKING_MANUAL_HARDCORE=&gt;LTCL_TEST" status="ERR">
      <system-err>True expected
Test 'LTCL_TEST-&gt;DO_THE_FAIL' in Main Program 'ZCL_THEKING_MANUAL_HARDCORE===CP'.</system-err>
      <error type="failedAssertion" message="Critical Assertion Error: 'I am supposed to fail'">Include: &lt;ZCL_THEKING_MANUAL_HARDCORE===CCAU&gt; Line: &lt;19&gt; (DO_THE_FAIL)</error>
    </testcase>
    <testcase name="DO_THE_WARN" classname="ZCL_THEKING_MANUAL_HARDCORE=&gt;LTCL_TEST" status="SKIP">
      <system-err>True expected
Test 'LTCL_TEST-&gt;DO_THE_WARN' in Main Program 'ZCL_THEKING_MANUAL_HARDCORE===CP'.</system-err>
      <error type="failedAssertion" message="Warning: 'I am supposed to warn'">Include: &lt;ZCL_THEKING_MANUAL_HARDCORE===CCAU&gt; Line: &lt;19&gt; (DO_THE_WARN)</error>
    </testcase>
    <testcase name="DO_THE_TEST" classname="ZCL_THEKING_MANUAL_HARDCORE=&gt;LTCL_TEST" status="OK"/>
  </testsuite>
  <testsuite name="LTCL_TEST_HARDER" package="ZCL_THEKING_MANUAL_HARDCORE" tests="2">
    <testcase name="DO_THE_FAIL" classname="ZCL_THEKING_MANUAL_HARDCORE=&gt;LTCL_TEST_HARDER" status="ERR">
      <system-err>True expected
Test 'LTCL_TEST_HARDER-&gt;DO_THE_FAIL' in Main Program 'ZCL_THEKING_MANUAL_HARDCORE===CP'.</system-err>
      <error type="failedAssertion" message="Critical Assertion Error: 'I am supposed to fail'">Include: &lt;ZCL_THEKING_MANUAL_HARDCORE===CCAU&gt; Line: &lt;19&gt; (DO_THE_FAIL)</error>
    </testcase>
    <testcase name="DO_THE_TEST" classname="ZCL_THEKING_MANUAL_HARDCORE=&gt;LTCL_TEST_HARDER" status="OK"/>
  </testsuite>
  <testsuite name="LTCL_TEST" package="ZEXAMPLE_TESTS" tests="2">
    <testcase name="DO_THE_FAIL" classname="ZEXAMPLE_TESTS=&gt;LTCL_TEST" status="ERR">
      <system-err>True expected
Test 'LTCL_TEST-&gt;DO_THE_FAIL' in Main Program 'ZEXAMPLE_TESTS'.</system-err>
      <error type="failedAssertion" message="Critical Assertion Error: 'I am supposed to fail'">Include: &lt;ZEXAMPLE_TESTS&gt; Line: &lt;24&gt; (DO_THE_FAIL)
Include: &lt;ZEXAMPLE_TESTS&gt; Line: &lt;25&gt; (PREPARE_THE_FAIL)</error>
      <error type="failedAssertion" message="Error&lt;LOAD_PROGRAM_CLASS_MISMATCH&gt;"/>
    </testcase>
    <testcase name="DO_THE_TEST" classname="ZEXAMPLE_TESTS=&gt;LTCL_TEST" status="OK"/>
  </testsuite>
</testsuites>
''')

    def test_aunit_package_with_results_sonar(self):
        self.connection.set_responses(Response(status_code=200, text=AUNIT_RESULTS_XML, headers={}))

        with patch('sys.stdout', new_callable=StringIO) as mock_stdout:
            exit_code = self.execute_run('package', 'ypackage', '--output', 'sonar', '--result', ResultOptions.ONLY_UNIT.value)

        self.assertEqual(exit_code, 3)
        self.assertEqual(len(self.connection.execs), 1)
        self.assertIn('packages/ypackage', self.connection.execs[0].body)

        self.maxDiff = None
        self.assertEqual(mock_stdout.getvalue(),
'''<?xml version="1.0" encoding="UTF-8" ?>
<testExecutions version="1">
  <file path="ypackage/ZCL_THEKING_MANUAL_HARDCORE=&gt;LTCL_TEST">
    <testCase name="DO_THE_FAIL" duration="33">
      <error message="Critical Assertion Error: 'I am supposed to fail'">
True expected
Test 'LTCL_TEST-&gt;DO_THE_FAIL' in Main Program 'ZCL_THEKING_MANUAL_HARDCORE===CP'.

Include: &lt;ZCL_THEKING_MANUAL_HARDCORE===CCAU&gt; Line: &lt;19&gt; (DO_THE_FAIL)
      </error>
    </testCase>
    <testCase name="DO_THE_WARN" duration="33">
      <skipped message="Warning: 'I am supposed to warn'">
True expected
Test 'LTCL_TEST-&gt;DO_THE_WARN' in Main Program 'ZCL_THEKING_MANUAL_HARDCORE===CP'.

Include: &lt;ZCL_THEKING_MANUAL_HARDCORE===CCAU&gt; Line: &lt;19&gt; (DO_THE_WARN)
      </skipped>
    </testCase>
    <testCase name="DO_THE_TEST" duration="0"/>
  </file>
  <file path="ypackage/ZCL_THEKING_MANUAL_HARDCORE=&gt;LTCL_TEST_HARDER">
    <testCase name="DO_THE_FAIL" duration="0">
      <error message="Critical Assertion Error: 'I am supposed to fail'">
True expected
Test 'LTCL_TEST_HARDER-&gt;DO_THE_FAIL' in Main Program 'ZCL_THEKING_MANUAL_HARDCORE===CP'.

Include: &lt;ZCL_THEKING_MANUAL_HARDCORE===CCAU&gt; Line: &lt;19&gt; (DO_THE_FAIL)
      </error>
    </testCase>
    <testCase name="DO_THE_TEST" duration="0"/>
  </file>
  <file path="ypackage/ZEXAMPLE_TESTS=&gt;LTCL_TEST">
    <testCase name="DO_THE_FAIL" duration="0">
      <error message="Critical Assertion Error: 'I am supposed to fail'">
True expected
Test 'LTCL_TEST-&gt;DO_THE_FAIL' in Main Program 'ZEXAMPLE_TESTS'.

Include: &lt;ZEXAMPLE_TESTS&gt; Line: &lt;24&gt; (DO_THE_FAIL)
Include: &lt;ZEXAMPLE_TESTS&gt; Line: &lt;25&gt; (PREPARE_THE_FAIL)
      </error>
      <error message="Error&lt;LOAD_PROGRAM_CLASS_MISMATCH&gt;">
      </error>
    </testCase>
    <testCase name="DO_THE_TEST" duration="0"/>
  </file>
</testExecutions>
''')

    def test_aunit_parser_results_global_class_tests(self):
        results = sap.adt.aunit.parse_aunit_response(GLOBAL_TEST_CLASS_AUNIT_RESULTS_XML).run_results
        output = StringIO()
        sap.cli.aunit.print_aunit_junit4(results, SimpleNamespace(name=['$TMP']), output)

        self.maxDiff = None
        self.assertEqual(output.getvalue(),
'''<?xml version="1.0" encoding="UTF-8" ?>
<testsuites name="$TMP">
  <testsuite name="ZCL_TEST_CLASS" package="ZCL_TEST_CLASS" tests="1">
    <testcase name="DO_THE_TEST" classname="ZCL_TEST_CLASS" status="OK"/>
  </testsuite>
</testsuites>
''')

    def test_aunit_parser_results_global_class_tests_multiple_targets(self):
        results = sap.adt.aunit.parse_aunit_response(GLOBAL_TEST_CLASS_AUNIT_RESULTS_XML)
        output = StringIO()
        sap.cli.aunit.print_aunit_junit4(results.run_results, SimpleNamespace(name=['$TMP', '$LOCAL', '$BAR']), output)

        self.maxDiff = None
        self.assertEqual(output.getvalue(),
'''<?xml version="1.0" encoding="UTF-8" ?>
<testsuites name="$TMP|$LOCAL|$BAR">
  <testsuite name="ZCL_TEST_CLASS" package="ZCL_TEST_CLASS" tests="1">
    <testcase name="DO_THE_TEST" classname="ZCL_TEST_CLASS" status="OK"/>
  </testsuite>
</testsuites>
''')

    def test_aunit_parser_results_global_class_tests_sonar(self):
        results = sap.adt.aunit.parse_aunit_response(GLOBAL_TEST_CLASS_AUNIT_RESULTS_XML).run_results
        output = StringIO()
        sap.cli.aunit.print_aunit_sonar(results, SimpleNamespace(name=['$TMP']), output)

        self.maxDiff = None
        self.assertEqual(output.getvalue(),
'''<?xml version="1.0" encoding="UTF-8" ?>
<testExecutions version="1">
  <file path="$TMP/ZCL_TEST_CLASS=&gt;ZCL_TEST_CLASS">
    <testCase name="DO_THE_TEST" duration="0"/>
    <testCase name="ZCL_TEST_CLASS" duration="0">
      <skipped message="The global test class [ZCL_TEST_CLASS] is not abstract">
You can find further informations in document &lt;CHAP&gt; &lt;SAUNIT_TEST_CL_POOL&gt;
      </skipped>
    </testCase>
  </file>
</testExecutions>
''')

    @patch('os.walk')
    def test_print_aunit_sonar_filename_is_not_none(self, walk):
        walk.return_value = [('.', None, ['zcl_theking_manual_hardcore.clas.testclasses.abap', 'bar'])]
        results = sap.adt.aunit.parse_aunit_response(AUNIT_RESULTS_NO_TEST_METHODS_XML).run_results
        output = StringIO()
        sap.cli.aunit.print_aunit_sonar(results, SimpleNamespace(name=['foo']), output)

        self.assertEqual(
            '''<?xml version="1.0" encoding="UTF-8" ?>
<testExecutions version="1">
  <file path="zcl_theking_manual_hardcore.clas.testclasses.abap">
  </file>
</testExecutions>
''',
            output.getvalue()
        )

    def test_print_acoverage_output_raises(self):
        with self.assertRaises(SAPCliError) as cm:
            sap.cli.aunit.print_acoverage_output(SimpleNamespace(coverage_output='foo'), Mock(), Mock(), Mock())

        self.assertEqual(str(cm.exception), 'Unsupported output type: foo')

    @patch('sap.cli.aunit.get_acoverage_statements')
    def test_acoverage_package_with_results_raw(self, get_acoverage_statements):
        get_acoverage_statements.return_value = []

        self.connection.set_responses(
            Response(status_code=200, text=AUNIT_RESULTS_XML, headers={}),
            Response(status_code=200, text=ACOVERAGE_RESULTS_XML, headers={})
        )

        with patch('sap.cli.aunit.print') as mock_print:
            exit_code = self.execute_run(
                'package', 'ypackage', '--coverage-output', 'raw', '--result', ResultOptions.ONLY_COVERAGE.value
            )

        self.assertEqual(exit_code, None)
        self.assertEqual(len(self.connection.execs), 2)

        self.assertEqual(mock_print.call_args_list[0], call(ACOVERAGE_RESULTS_XML, file=sys.stdout))

    @patch('sap.cli.aunit.get_acoverage_statements')
    def test_acoverage_package_with_results_human(self, get_acoverage_statements):
        get_acoverage_statements.return_value = []

        self.connection.set_responses(
            Response(status_code=200, text=AUNIT_RESULTS_XML, headers={}),
            Response(status_code=200, text=ACOVERAGE_RESULTS_XML, headers={})
        )

        with patch('sys.stdout', new_callable=StringIO) as mock_stdout:
            exit_code = self.execute_run(
                'package', 'ypackage', '--coverage-output', 'human', '--result', ResultOptions.ONLY_COVERAGE.value
            )

        self.assertEqual(exit_code, None)
        self.assertEqual(len(self.connection.execs), 2)

        self.assertEqual(mock_stdout.getvalue(),
'''TEST_CHECK_LIST : 29.00%
  FOO===========================CP : 95.24%
    FOO : 95.24%
      METHOD_A : 100.00%
      METHOD_B : 75.00%
  BAR===========================CP : 0.00%
''')

    def test_acoverage_package_with_results_jacoco(self):
        self.connection.set_responses(
            Response(status_code=200, text=AUNIT_RESULTS_XML, headers={}),
            Response(status_code=200, text=ACOVERAGE_RESULTS_XML, headers={}),
            Response(status_code=200, text=ACOVERAGE_STATEMENTS_RESULTS_XML, headers={}),
        )

        with patch('sys.stdout', new_callable=StringIO) as mock_stdout:
            exit_code = self.execute_run(
                'package', 'ypackage', '--coverage-output', 'jacoco', '--result', ResultOptions.ONLY_COVERAGE.value
            )

        self.assertEqual(exit_code, None)
        self.assertEqual(len(self.connection.execs), 3)
        self.assertEqual(mock_stdout.getvalue(),
'''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.1//EN" "report.dtd">
<report name="ypackage">
   <package name="TEST_CHECK_LIST">
      <class name="FOO" sourcefilename="FOO">
         <method name="METHOD_A" line="52">
            <counter type="BRANCH" missed="2" covered="3"/>
            <counter type="METHOD" missed="0" covered="1"/>
            <counter type="INSTRUCTION" missed="0" covered="5"/>
         </method>
         <method name="METHOD_B" line="199">
            <counter type="BRANCH" missed="1" covered="1"/>
            <counter type="METHOD" missed="0" covered="1"/>
            <counter type="INSTRUCTION" missed="2" covered="6"/>
         </method>
         <counter type="BRANCH" missed="7" covered="22"/>
         <counter type="METHOD" missed="0" covered="8"/>
         <counter type="INSTRUCTION" missed="3" covered="60"/>
      </class>
      <sourcefile name="FOO">
         <line nr="53" mi="0" ci="1"/>
         <line nr="54" mi="0" ci="1"/>
         <line nr="55" mi="0" ci="1"/>
         <line nr="56" mi="0" ci="1"/>
         <line nr="59" mi="0" ci="1"/>
         <line nr="209" mi="0" ci="1"/>
         <line nr="212" mi="0" ci="1"/>
         <line nr="215" mi="0" ci="1"/>
         <line nr="216" mi="0" ci="1"/>
         <line nr="219" mi="0" ci="1"/>
         <line nr="220" mi="0" ci="1"/>
         <line nr="224" mi="1" ci="0"/>
         <line nr="225" mi="1" ci="0"/>
      </sourcefile>
      <class name="BAR" sourcefilename="BAR">
         <counter type="BRANCH" missed="0" covered="0"/>
         <counter type="METHOD" missed="0" covered="0"/>
         <counter type="INSTRUCTION" missed="0" covered="0"/>
      </class>
      <counter type="BRANCH" missed="105" covered="29"/>
      <counter type="METHOD" missed="42" covered="10"/>
      <counter type="INSTRUCTION" missed="235" covered="96"/>
   </package>
</report>
''')

    def test_result_option_all(self):
        self.connection.set_responses(
            Response(status_code=200, text=AUNIT_RESULTS_XML, headers={}),
            Response(status_code=200, text=ACOVERAGE_RESULTS_XML, headers={}),
            Response(status_code=200, text=ACOVERAGE_STATEMENTS_RESULTS_XML, headers={}),
        )

        with patch('sap.cli.aunit.print') as mock_print:
            exit_code = self.execute_run(
                'package', 'ypackage', '--output', 'raw', '--coverage-output', 'raw', '--result', ResultOptions.ALL.value
            )

        self.assertEqual(exit_code, 3)
        self.assertEqual(len(self.connection.execs), 3)

        self.assertEqual(len(mock_print.call_args_list), 2)
        self.assertEqual(mock_print.call_args_list[0], call(AUNIT_RESULTS_XML, file=sys.stdout))
        self.assertEqual(mock_print.call_args_list[1], call(ACOVERAGE_RESULTS_XML, file=sys.stdout))

    def test_result_option_unit(self):
        self.connection.set_responses(
            Response(status_code=200, text=AUNIT_RESULTS_XML, headers={})
        )

        with patch('sap.cli.aunit.print') as mock_print:
            exit_code = self.execute_run(
                'package', 'ypackage', '--output', 'raw', '--coverage-output', 'raw', '--result', ResultOptions.ONLY_UNIT.value
            )

        self.assertEqual(exit_code, 3)
        self.assertEqual(len(self.connection.execs), 1)

        self.assertEqual(len(mock_print.call_args_list), 1)
        self.assertEqual(mock_print.call_args_list[0], call(AUNIT_RESULTS_XML, file=sys.stdout))

    def test_result_option_coverage(self):
        self.connection.set_responses(
            Response(status_code=200, text=AUNIT_RESULTS_XML, headers={}),
            Response(status_code=200, text=ACOVERAGE_RESULTS_XML, headers={}),
            Response(status_code=200, text=ACOVERAGE_STATEMENTS_RESULTS_XML, headers={}),
        )

        with patch('sap.cli.aunit.print') as mock_print:
            exit_code = self.execute_run(
                'package', 'ypackage', '--output', 'raw', '--coverage-output', 'raw', '--result', ResultOptions.ONLY_COVERAGE.value
            )

        self.assertEqual(exit_code, None)
        self.assertEqual(len(self.connection.execs), 3)

        self.assertEqual(len(mock_print.call_args_list), 1)
        self.assertEqual(mock_print.call_args_list[0], call(ACOVERAGE_RESULTS_XML, file=sys.stdout))

    def test_coverage_filepath(self):
        self.connection.set_responses(
            Response(status_code=200, text=AUNIT_RESULTS_XML, headers={}),
            Response(status_code=200, text=ACOVERAGE_RESULTS_XML, headers={}),
            Response(status_code=200, text=ACOVERAGE_STATEMENTS_RESULTS_XML, headers={}),
        )

        coverage_filepath = 'path/to/coverage'
        with patch('sap.cli.aunit.open', mock_open()) as mock_file:
            exit_code = self.execute_run(
                'package', 'ypackage', '--output', 'raw', '--coverage-output', 'raw', '--result', ResultOptions.ONLY_COVERAGE.value,
                '--coverage-filepath', coverage_filepath
            )

        mock_file.assert_called_with(coverage_filepath, 'w+')

    def test_aunit_parser_results_global_class_tests_sonar_multiple_targets(self):
        results = sap.adt.aunit.parse_aunit_response(GLOBAL_TEST_CLASS_AUNIT_RESULTS_XML)
        output = StringIO()
        sap.cli.aunit.print_aunit_sonar(results.run_results, SimpleNamespace(name=['$LOCAL', '$TMP']), output)

        self.maxDiff = None
        self.assertEqual(output.getvalue(),
'''<?xml version="1.0" encoding="UTF-8" ?>
<testExecutions version="1">
  <file path="UNKNOWN_PACKAGE/ZCL_TEST_CLASS=&gt;ZCL_TEST_CLASS">
    <testCase name="DO_THE_TEST" duration="0"/>
    <testCase name="ZCL_TEST_CLASS" duration="0">
      <skipped message="The global test class [ZCL_TEST_CLASS] is not abstract">
You can find further informations in document &lt;CHAP&gt; &lt;SAUNIT_TEST_CL_POOL&gt;
      </skipped>
    </testCase>
  </file>
</testExecutions>
''')