<s> import os <EOL> from nose2 . tests . _common import FunctionalTestCase <EOL> from nose2 . tests . _common import TestCase <EOL> from nose2 . tests . _common import support_file <EOL> from xml . etree import ElementTree as ET <EOL> class JunitXmlPluginFunctionalTest ( FunctionalTestCase , TestCase ) : <EOL> _RUN_IN_TEMP = True <EOL> def run_with_junitxml_loaded ( self , scenario , * args ) : <EOL> work_dir = os . getcwd ( ) <EOL> test_dir = support_file ( * scenario ) <EOL> junit_report = os . path . join ( work_dir , '<STR_LIT>' ) <EOL> config = os . path . join ( test_dir , '<STR_LIT>' ) <EOL> config_args = ( ) <EOL> if os . path . exists ( junit_report ) : <EOL> os . remove ( junit_report ) <EOL> if os . path . exists ( config ) : <EOL> config_args = ( '<STR_LIT:-c>' , config ) <EOL> proc = self . runIn ( work_dir , <EOL> '<STR_LIT>' % test_dir , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> * ( config_args + args ) ) <EOL> return junit_report , proc <EOL> def test_invocation_by_double_dash_option ( self ) : <EOL> junit_report , proc = self . run_with_junitxml_loaded ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , stderr = '<STR_LIT>' ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , stderr = '<STR_LIT>' ) <EOL> self . assertEqual ( proc . poll ( ) , <NUM_LIT:0> ) <EOL> self . assertTrue ( os . path . isfile ( junit_report ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + junit_report ) <EOL> def test_invocation_by_single_dash_option ( self ) : <EOL> junit_report , proc = self . run_with_junitxml_loaded ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , stderr = '<STR_LIT>' ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , stderr = '<STR_LIT>' ) <EOL> self . assertEqual ( proc . poll ( ) , <NUM_LIT:0> ) <EOL> self . assertTrue ( os . path . isfile ( junit_report ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + junit_report ) <EOL> def test_no_report_written_if_loaded_but_not_invoked ( self ) : <EOL> junit_report , proc = self . run_with_junitxml_loaded ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , stderr = '<STR_LIT>' ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , stderr = '<STR_LIT>' ) <EOL> self . assertEqual ( proc . poll ( ) , <NUM_LIT:0> ) <EOL> self . assertFalse ( os . path . isfile ( junit_report ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + junit_report ) <EOL> def test_report_location_should_be_resilent_to_chdir_in_tests ( self ) : <EOL> junit_report , proc = self . run_with_junitxml_loaded ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , <EOL> stderr = '<STR_LIT>' ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , stderr = '<STR_LIT>' ) <EOL> self . assertEqual ( proc . poll ( ) , <NUM_LIT:0> ) <EOL> self . assertTrue ( os . path . isfile ( junit_report ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + junit_report ) <EOL> def test_report_includes_properties ( self ) : <EOL> scenario = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> work_dir = os . getcwd ( ) <EOL> with open ( os . path . join ( work_dir , '<STR_LIT>' ) , '<STR_LIT:w>' ) as fh : <EOL> fh . write ( '<STR_LIT>' ) <EOL> junit_report , proc = self . run_with_junitxml_loaded ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , <EOL> stderr = '<STR_LIT>' ) <EOL> self . assertEqual ( proc . poll ( ) , <NUM_LIT:0> ) <EOL> with open ( junit_report , '<STR_LIT:r>' ) as fh : <EOL> tree = ET . parse ( fh ) . getroot ( ) <EOL> self . assertEqual ( len ( tree . findall ( '<STR_LIT>' ) ) , <NUM_LIT:1> ) <EOL> prop = tree . find ( '<STR_LIT>' ) . find ( '<STR_LIT>' ) <EOL> assert '<STR_LIT:name>' in prop . attrib <EOL> assert '<STR_LIT:value>' in prop . attrib <EOL> self . assertEqual ( prop . get ( '<STR_LIT:name>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( prop . get ( '<STR_LIT:value>' ) , '<STR_LIT>' ) <EOL> class JunitXmlPluginFunctionalFailureTest ( FunctionalTestCase , TestCase ) : <EOL> def test_failure_to_write_report ( self ) : <EOL> proc = self . runIn ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( proc . poll ( ) , <NUM_LIT:1> ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , <EOL> stderr = '<STR_LIT>' ) <EOL> filename_for_regex = os . path . abspath ( '<STR_LIT>' ) <EOL> filename_for_regex = filename_for_regex . replace ( '<STR_LIT:\\>' , r'<STR_LIT>' ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , stderr = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % filename_for_regex ) <EOL> def test_failure_to_read_missing_properties ( self ) : <EOL> proc = self . runIn ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( proc . poll ( ) , <NUM_LIT:1> ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , <EOL> stderr = '<STR_LIT>' ) <EOL> filename_for_regex = os . path . join ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> filename_for_regex = filename_for_regex . replace ( '<STR_LIT:\\>' , r'<STR_LIT>' ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , stderr = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % filename_for_regex ) <EOL> def test_failure_to_read_empty_properties ( self ) : <EOL> proc = self . runIn ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( proc . poll ( ) , <NUM_LIT:1> ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , <EOL> stderr = '<STR_LIT>' ) <EOL> filename_for_regex = os . path . join ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> filename_for_regex = filename_for_regex . replace ( '<STR_LIT:\\>' , r'<STR_LIT:\\>' ) <EOL> self . assertTestRunOutputMatches ( <EOL> proc , stderr = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % filename_for_regex ) </s>
