1717
1818ROOT = dirname (dirname (dirname (abspath (__file__ ))))
1919TEMP = tempfile .gettempdir ()
20+ OUTPUT_PATH = join (TEMP , 'output.xml' )
21+ REPORT_PATH = join (TEMP , 'report.html' )
2022LOG_PATH = join (TEMP , 'log.html' )
2123LOG = 'Log: %s' % LOG_PATH
2224
@@ -45,7 +47,7 @@ class TestRun(RunningTestCase):
4547 data = join (ROOT , 'atest' , 'testdata' , 'misc' , 'pass_and_fail.robot' )
4648 warn = join (ROOT , 'atest' , 'testdata' , 'misc' , 'warnings_and_errors.robot' )
4749 nonex = join (TEMP , 'non-existing-file-this-is.robot' )
48- remove_files = [LOG_PATH ]
50+ remove_files = [LOG_PATH , REPORT_PATH , OUTPUT_PATH ]
4951
5052 def test_run_once (self ):
5153 assert_equals (run (self .data , outputdir = TEMP , report = 'none' ), 1 )
@@ -57,11 +59,13 @@ def test_run_multiple_times(self):
5759 assert_equals (run_without_outputs (self .data , name = 'New Name' ), 1 )
5860 self ._assert_outputs ([('Pass And Fail' , 2 ), ('New Name' , 2 ), (LOG , 0 )])
5961
60- def test_run_fails (self ):
61- assert_equals (run (self .nonex ), 252 )
62+ def test_run_fail (self ):
6263 assert_equals (run (self .data , outputdir = TEMP ), 1 )
63- self ._assert_outputs (stdout = [('Pass And Fail' , 2 ), (LOG , 1 )],
64- stderr = [('[ ERROR ]' , 1 ), (self .nonex , 1 ),
64+ self ._assert_outputs (stdout = [('Pass And Fail' , 2 ), (LOG , 1 )])
65+
66+ def test_run_error (self ):
67+ assert_equals (run (self .nonex ), 252 )
68+ self ._assert_outputs (stderr = [('[ ERROR ]' , 1 ), (self .nonex , 1 ),
6569 ('--help' , 1 )])
6670
6771 def test_custom_stdout (self ):
@@ -90,14 +94,6 @@ def test_multi_options_as_single_string(self):
9094 assert_equals (run_without_outputs (self .data , exclude = 'fail' ), 0 )
9195 self ._assert_outputs ([('FAIL' , 0 )])
9296
93- def test_listeners_unregistration (self ):
94- module_file = join (ROOT , 'utest' , 'resources' , 'Listener.py' )
95- assert_equals (run_without_outputs (self .data , listener = [module_file + ":1" ]), 1 )
96- self ._assert_outputs ([("[from listener 1]" , 1 ), ("[listener close]" , 1 )])
97- self ._clear_outputs ()
98- assert_equals (run_without_outputs (self .data ), 1 )
99- self ._assert_outputs ([("[from listener 1]" , 0 ), ("[listener close]" , 0 )])
100-
10197
10298class TestRebot (RunningTestCase ):
10399 data = join (ROOT , 'atest' , 'testdata' , 'rebot' , 'created_normal.xml' )
@@ -128,7 +124,7 @@ def test_custom_stdout(self):
128124 self ._assert_output (stdout , [('Log:' , 1 ), ('Report:' , 0 )])
129125 self ._assert_outputs ()
130126
131- def test_custom_stdout_and_stderr_with_minumal_implementation (self ):
127+ def test_custom_stdout_and_stderr_with_minimal_implementation (self ):
132128 output = StreamWithOnlyWriteAndFlush ()
133129 assert_equals (rebot (self .data , log = 'NONE' , report = 'NONE' , stdout = output ,
134130 stderr = output ), 252 )
@@ -139,20 +135,19 @@ def test_custom_stdout_and_stderr_with_minumal_implementation(self):
139135 self ._assert_outputs ()
140136
141137
142- class TestStateBetweenTestRuns (unittest .TestCase ):
138+ class TestStateBetweenTestRuns (RunningTestCase ):
139+ data = join (ROOT , 'atest' , 'testdata' , 'misc' , 'normal.robot' )
143140
144141 def test_importer_caches_are_cleared_between_runs (self ):
145- data = join (ROOT , 'atest' , 'testdata' , 'misc' , 'normal.robot' )
146- self ._run (data )
142+ self ._run (self .data )
147143 lib = self ._import_library ()
148144 res = self ._import_resource ()
149- self ._run (data )
145+ self ._run (self . data )
150146 assert_true (lib is not self ._import_library ())
151147 assert_true (res is not self ._import_resource ())
152148
153149 def _run (self , data , ** config ):
154- return run_without_outputs (data , stdout = StringIO (), stderr = StringIO (),
155- outputdir = TEMP , ** config )
150+ return run_without_outputs (data , outputdir = TEMP , ** config )
156151
157152 def _import_library (self ):
158153 return namespace .IMPORTER .import_library ('BuiltIn' , None , None , None )
@@ -175,6 +170,14 @@ def test_reset_logging_conf(self):
175170 assert_equals (logging .getLogger ().handlers , [])
176171 assert_equals (logging .raiseExceptions , 1 )
177172
173+ def test_listener_unregistration (self ):
174+ listener = join (ROOT , 'utest' , 'resources' , 'Listener.py' )
175+ assert_equals (run_without_outputs (self .data , listener = listener + ':1' ), 0 )
176+ self ._assert_outputs ([("[from listener 1]" , 1 ), ("[listener close]" , 1 )])
177+ self ._clear_outputs ()
178+ assert_equals (run_without_outputs (self .data ), 0 )
179+ self ._assert_outputs ([("[from listener 1]" , 0 ), ("[listener close]" , 0 )])
180+
178181
179182class TestTimestampOutputs (RunningTestCase ):
180183 output = join (TEMP , 'output-ts-*.xml' )
@@ -240,7 +243,7 @@ def test_dont_register_signal_handlers_then_run_on_thread(self):
240243
241244
242245class TestRelativeImportsFromPythonpath (RunningTestCase ):
243- _data = join (abspath (dirname (__file__ )), 'import_test.robot' )
246+ data = join (abspath (dirname (__file__ )), 'import_test.robot' )
244247
245248 def setUp (self ):
246249 self ._orig_path = abspath (curdir )
@@ -253,7 +256,7 @@ def tearDown(self):
253256
254257 def test_importing_library_from_pythonpath (self ):
255258 errors = StringIO ()
256- run (self ._data , outputdir = TEMP , stdout = StringIO (), stderr = errors )
259+ run (self .data , outputdir = TEMP , stdout = StringIO (), stderr = errors )
257260 self ._assert_output (errors , '' )
258261
259262
0 commit comments