Lines Matching refs:self
17 def __init__(self, path, is_writable=False): argument
22 self.path = tempfile.mktemp()
24 self.path = path
32 def __init__(self): argument
33 self._state = {}
34 self._backing_file_lock = None
36 def read_from_file(self, file_path): argument
39 def write_to_file(self, file_path): argument
42 def set_backing_file(self, file_path): argument
45 def _read_from_backing_file(self): argument
48 def _write_to_backing_file(self): argument
51 def _lock_backing_file(self): argument
54 def _unlock_backing_file(self): argument
100 def test_public_attributes_initialized(self): argument
102 self.call_init()
103 public_attributes = set(attr for attr in dir(self.job)
105 and not callable(getattr(self.job, attr)))
106 expected_attributes = self.PUBLIC_ATTRIBUTES
108 self.assertEqual(missing_attributes, set([]),
112 self.OPTIONAL_ATTRIBUTES_DEVICE_ERROR)
113 self.assertEqual(extra_attributes, set([]),
118 def test_required_attributes_not_none(self): argument
119 required_attributes = (self.PUBLIC_ATTRIBUTES -
120 self.OPTIONAL_ATTRIBUTES)
121 self.call_init()
123 self.assertNotEqual(getattr(self.job, attribute, None), None,
137 def test_autodir_is_not_none(self): argument
138 auto, client, server = self.job._find_base_directories()
139 self.assertNotEqual(auto, None)
142 def test_clientdir_is_not_none(self): argument
143 auto, client, server = self.job._find_base_directories()
144 self.assertNotEqual(client, None)
148 def make_job(self, autodir, server): argument
163 def setUp(self): argument
164 self.cjob = self.make_job('/atest/client', False)
165 self.sjob = self.make_job('/atest', True)
168 def test_always_client_dirs(self): argument
169 self.cjob._initialize_dir_properties()
170 self.sjob._initialize_dir_properties()
173 self.assertEqual(self.cjob.bindir, self.sjob.bindir)
174 self.assertEqual(self.cjob.profdir, self.sjob.profdir)
175 self.assertEqual(self.cjob.pkgdir, self.sjob.pkgdir)
178 def test_dynamic_dirs(self): argument
179 self.cjob._initialize_dir_properties()
180 self.sjob._initialize_dir_properties()
183 self.assert_(self.cjob.tmpdir.startswith('/atest/client'))
184 self.assert_(self.cjob.testdir.startswith('/atest/client'))
185 self.assert_(self.cjob.site_testdir.startswith('/atest/client'))
186 self.assertEqual(self.sjob.tmpdir, tempfile.gettempdir())
187 self.assert_(self.sjob.testdir.startswith('/atest/server'))
188 self.assert_(self.sjob.site_testdir.startswith('/atest/server'))
192 def setUp(self): argument
194 self.resultdir = tempfile.mkdtemp(suffix='unittest')
195 self.job = base_job.base_job.__new__(base_job.base_job)
196 self.job._find_base_directories = lambda: (clientdir, clientdir, None)
197 self.job._find_resultdir = lambda *_: self.resultdir
198 self.job.__init__()
201 def tearDown(self): argument
202 shutil.rmtree(self.resultdir, ignore_errors=True)
205 def test_pop_fails_without_push(self): argument
206 self.assertRaises(IndexError, self.job.pop_execution_context)
209 def test_push_changes_to_subdir(self): argument
210 sub1 = os.path.join(self.resultdir, 'sub1')
212 self.job.push_execution_context('sub1')
213 self.assertEqual(self.job.resultdir, sub1)
216 def test_push_creates_subdir(self): argument
217 sub2 = os.path.join(self.resultdir, 'sub2')
218 self.job.push_execution_context('sub2')
219 self.assertEqual(self.job.resultdir, sub2)
220 self.assert_(os.path.exists(sub2))
223 def test_push_handles_absolute_paths(self): argument
226 self.job.push_execution_context(otherresults)
227 self.assertEqual(self.job.resultdir, otherresults)
232 def test_pop_restores_context(self): argument
233 sub3 = os.path.join(self.resultdir, 'sub3')
234 self.job.push_execution_context('sub3')
235 self.assertEqual(self.job.resultdir, sub3)
236 self.job.pop_execution_context()
237 self.assertEqual(self.job.resultdir, self.resultdir)
240 def test_push_and_pop_are_fifo(self): argument
241 sub4 = os.path.join(self.resultdir, 'sub4')
243 self.job.push_execution_context('sub4')
244 self.assertEqual(self.job.resultdir, sub4)
245 self.job.push_execution_context('subsub')
246 self.assertEqual(self.job.resultdir, subsub)
247 self.job.pop_execution_context()
248 self.assertEqual(self.job.resultdir, sub4)
249 self.job.pop_execution_context()
250 self.assertEqual(self.job.resultdir, self.resultdir)
254 def setUp(self): argument
255 self.testdir = tempfile.mkdtemp(suffix='unittest')
256 self.original_wd = os.getcwd()
257 os.chdir(self.testdir)
260 def tearDown(self): argument
261 os.chdir(self.original_wd)
262 shutil.rmtree(self.testdir, ignore_errors=True)
265 def test_passes_if_dir_exists(self): argument
267 self.assert_(os.path.isdir('testing'))
269 self.assert_(os.path.isdir('testing'))
272 def test_fails_if_not_writable_and_dir_doesnt_exist(self): argument
273 self.assert_(not os.path.isdir('testing2'))
274 self.assertRaises(base_job.job_directory.MissingDirectoryException,
278 def test_fails_if_file_already_exists(self): argument
280 self.assert_(os.path.isfile('testing3'))
281 self.assertRaises(base_job.job_directory.MissingDirectoryException,
285 def test_passes_if_writable_and_dir_exists(self): argument
287 self.assert_(os.path.isdir('testing4'))
289 self.assert_(os.path.isdir('testing4'))
292 def test_creates_dir_if_writable_and_dir_doesnt_exist(self): argument
293 self.assert_(not os.path.isdir('testing5'))
295 self.assert_(os.path.isdir('testing5'))
298 def test_recursive_creates_dir_if_writable_and_dir_doesnt_exist(self): argument
299 self.assert_(not os.path.isdir('testing6'))
301 self.assert_(os.path.isdir('testing6/subdir'))
304 def test_fails_if_writable_and_file_exists(self): argument
306 self.assert_(os.path.isfile('testing7'))
307 self.assert_(not os.path.isdir('testing7'))
308 self.assertRaises(base_job.job_directory.UncreatableDirectoryException,
312 def test_fails_if_writable_and_no_permission_to_create(self): argument
314 self.assert_(os.path.isdir('testing8'))
315 self.assertRaises(base_job.job_directory.UncreatableDirectoryException,
319 def test_passes_if_not_is_writable_and_dir_not_writable(self): argument
321 self.assert_(os.path.isdir('testing9'))
322 self.assert_(not os.access('testing9', os.W_OK))
326 def test_fails_if_is_writable_but_dir_not_writable(self): argument
328 self.assert_(os.path.isdir('testing10'))
329 self.assert_(not os.access('testing10', os.W_OK))
330 self.assertRaises(base_job.job_directory.UnwritableDirectoryException,
334 def test_fails_if_no_path_and_not_writable(self): argument
335 self.assertRaises(base_job.job_directory.MissingDirectoryException,
339 def test_no_path_and_and_not_writable_creates_tempdir(self): argument
341 self.assert_(os.path.isdir(jd.path))
342 self.assert_(os.access(jd.path, os.W_OK))
345 self.assert_(not os.path.isdir(temp_path))
349 def setUp(self): argument
350 self.state = base_job.job_state()
353 def test_undefined_name_returns_key_error(self): argument
354 self.assertRaises(KeyError, self.state.get, 'ns1', 'missing_name')
357 def test_undefined_name_returns_default(self): argument
358 self.assertEqual(42, self.state.get('ns2', 'missing_name', default=42))
361 def test_none_is_valid_default(self): argument
362 self.assertEqual(None, self.state.get('ns3', 'missing_name',
366 def test_get_returns_set_values(self): argument
367 self.state.set('ns4', 'name1', 50)
368 self.assertEqual(50, self.state.get('ns4', 'name1'))
371 def test_get_ignores_default_when_value_is_defined(self): argument
372 self.state.set('ns5', 'name2', 55)
373 self.assertEqual(55, self.state.get('ns5', 'name2', default=45))
376 def test_set_only_sets_one_value(self): argument
377 self.state.set('ns6', 'name3', 50)
378 self.assertEqual(50, self.state.get('ns6', 'name3'))
379 self.assertRaises(KeyError, self.state.get, 'ns6', 'name4')
382 def test_set_works_with_multiple_names(self): argument
383 self.state.set('ns7', 'name5', 60)
384 self.state.set('ns7', 'name6', 70)
385 self.assertEquals(60, self.state.get('ns7', 'name5'))
386 self.assertEquals(70, self.state.get('ns7', 'name6'))
389 def test_multiple_sets_override_each_other(self): argument
390 self.state.set('ns8', 'name7', 10)
391 self.state.set('ns8', 'name7', 25)
392 self.assertEquals(25, self.state.get('ns8', 'name7'))
395 def test_get_with_default_does_not_set(self): argument
396 self.assertEquals(100, self.state.get('ns9', 'name8', default=100))
397 self.assertRaises(KeyError, self.state.get, 'ns9', 'name8')
400 def test_set_in_one_namespace_ignores_other(self): argument
401 self.state.set('ns10', 'name9', 200)
402 self.assertEquals(200, self.state.get('ns10', 'name9'))
403 self.assertRaises(KeyError, self.state.get, 'ns11', 'name9')
406 def test_namespaces_do_not_collide(self): argument
407 self.state.set('ns12', 'name10', 250)
408 self.state.set('ns13', 'name10', -150)
409 self.assertEquals(-150, self.state.get('ns13', 'name10'))
410 self.assertEquals(250, self.state.get('ns12', 'name10'))
413 def test_discard_does_nothing_on_undefined_namespace(self): argument
414 self.state.discard('missing_ns', 'missing')
415 self.assertRaises(KeyError, self.state.get, 'missing_ns', 'missing')
418 def test_discard_does_nothing_on_missing_name(self): argument
419 self.state.set('ns14', 'name20', 111)
420 self.state.discard('ns14', 'missing')
421 self.assertEqual(111, self.state.get('ns14', 'name20'))
422 self.assertRaises(KeyError, self.state.get, 'ns14', 'missing')
425 def test_discard_deletes_name(self): argument
426 self.state.set('ns15', 'name21', 4567)
427 self.assertEqual(4567, self.state.get('ns15', 'name21'))
428 self.state.discard('ns15', 'name21')
429 self.assertRaises(KeyError, self.state.get, 'ns15', 'name21')
432 def test_discard_doesnt_touch_other_values(self): argument
433 self.state.set('ns16_1', 'name22', 'val1')
434 self.state.set('ns16_1', 'name23', 'val2')
435 self.state.set('ns16_2', 'name23', 'val3')
436 self.assertEqual('val1', self.state.get('ns16_1', 'name22'))
437 self.assertEqual('val3', self.state.get('ns16_2', 'name23'))
438 self.state.discard('ns16_1', 'name23')
439 self.assertEqual('val1', self.state.get('ns16_1', 'name22'))
440 self.assertEqual('val3', self.state.get('ns16_2', 'name23'))
443 def test_has_is_true_for_all_set_values(self): argument
444 self.state.set('ns17_1', 'name24', 1)
445 self.state.set('ns17_1', 'name25', 2)
446 self.state.set('ns17_2', 'name25', 3)
447 self.assert_(self.state.has('ns17_1', 'name24'))
448 self.assert_(self.state.has('ns17_1', 'name25'))
449 self.assert_(self.state.has('ns17_2', 'name25'))
452 def test_has_is_false_for_all_unset_values(self): argument
453 self.state.set('ns18_1', 'name26', 1)
454 self.state.set('ns18_1', 'name27', 2)
455 self.state.set('ns18_2', 'name27', 3)
456 self.assert_(not self.state.has('ns18_2', 'name26'))
459 def test_discard_namespace_drops_all_values(self): argument
460 self.state.set('ns19', 'var1', 10)
461 self.state.set('ns19', 'var3', 100)
462 self.state.discard_namespace('ns19')
463 self.assertRaises(KeyError, self.state.get, 'ns19', 'var1')
464 self.assertRaises(KeyError, self.state.get, 'ns19', 'var3')
467 def test_discard_namespace_works_on_missing_namespace(self): argument
468 self.state.discard_namespace('missing_ns')
471 def test_discard_namespace_doesnt_touch_other_values(self): argument
472 self.state.set('ns20', 'var1', 20)
473 self.state.set('ns20', 'var2', 200)
474 self.state.set('ns21', 'var2', 21)
475 self.state.discard_namespace('ns20')
476 self.assertEqual(21, self.state.get('ns21', 'var2'))
482 def setUp(self): argument
483 self.backing_file = tempfile.mktemp()
484 self.state = base_job.job_state()
485 self.state.set_backing_file(self.backing_file)
488 def tearDown(self): argument
489 if os.path.exists(self.backing_file):
490 os.remove(self.backing_file)
493 def test_set_is_persistent(self): argument
494 self.state.set('persist', 'var', 'value')
496 written_state.read_from_file(self.backing_file)
497 self.assertEqual('value', written_state.get('persist', 'var'))
500 def test_discard_is_persistent(self): argument
501 self.state.set('persist', 'var', 'value')
502 self.state.discard('persist', 'var')
504 written_state.read_from_file(self.backing_file)
505 self.assertRaises(KeyError, written_state.get, 'persist', 'var')
508 def test_discard_namespace_is_persistent(self): argument
509 self.state.set('persist', 'var', 'value')
510 self.state.discard_namespace('persist')
512 written_state.read_from_file(self.backing_file)
513 self.assertRaises(KeyError, written_state.get, 'persist', 'var')
517 def setUp(self): argument
518 self.testdir = tempfile.mkdtemp(suffix='unittest')
519 self.original_wd = os.getcwd()
520 os.chdir(self.testdir)
523 def tearDown(self): argument
524 os.chdir(self.original_wd)
525 shutil.rmtree(self.testdir, ignore_errors=True)
528 def test_write_read_transfers_all_state(self): argument
534 self.assertRaises(KeyError, state2.get, 'ns1', 'var0')
535 self.assertRaises(KeyError, state2.get, 'ns2', 'var10')
537 self.assertEqual(50, state2.get('ns1', 'var0'))
538 self.assertEqual(100, state2.get('ns2', 'var10'))
541 def test_read_overwrites_in_memory(self): argument
546 self.assertEqual('goodbye', state.get('ns', 'myvar'))
548 self.assertEqual('hello', state.get('ns', 'myvar'))
551 def test_read_updates_persistent_file(self): argument
562 self.assertEqual('value1', state3.get('ns', 'var1'))
563 self.assertEqual('value2', state3.get('ns', 'var2'))
566 def test_read_without_merge(self): argument
572 self.assertFalse(state.has('ns', 'myvar1'))
573 self.assertEqual('goodbye', state.get('ns', 'myvar2'))
575 self.assertEqual('hello', state.get('ns', 'myvar1'))
576 self.assertFalse(state.has('ns', 'myvar2'))
580 def setUp(self): argument
581 self.testdir = tempfile.mkdtemp(suffix='unittest')
582 self.original_wd = os.getcwd()
583 os.chdir(self.testdir)
586 def tearDown(self): argument
587 os.chdir(self.original_wd)
588 shutil.rmtree(self.testdir, ignore_errors=True)
591 def test_writes_to_file(self): argument
594 self.assert_(os.path.exists('outfile1'))
597 def test_set_backing_file_updates_existing_file(self): argument
609 self.assertEqual(0, state3.get('ns0', 'var0x'))
610 self.assertEqual(100, state3.get('ns0', 'var1x'))
613 def test_set_backing_file_does_not_overwrite_previous_backing_file(self): argument
625 self.assertEqual(-10, state3.get('ns0', 'var0y'))
626 self.assertRaises(KeyError, state3.get, 'ns0', 'var1y')
629 def test_writes_stop_after_backing_file_removed(self): argument
636 self.assert_(not os.path.exists('outfile2'))
639 def test_written_files_can_be_reloaded(self): argument
645 self.assertRaises(KeyError, state2.get, 'n3', 'var1')
647 self.assertEqual(67, state2.get('n3', 'var1'))
650 def test_backing_file_overrides_in_memory_values(self): argument
657 self.assertEqual(430, state2.get('n4', 'var1'))
659 self.assertEqual(42, state2.get('n4', 'var1'))
662 def test_backing_file_only_overrides_values_it_defines(self): argument
670 self.assertEqual(123, state2.get('n5', 'var1'))
671 self.assertEqual(456, state2.get('n5', 'var2'))
674 def test_shared_backing_file_propagates_state_to_get(self): argument
679 self.assertRaises(KeyError, state1.get, 'n6', 'shared1')
680 self.assertRaises(KeyError, state2.get, 'n6', 'shared1')
682 self.assertEqual(345, state1.get('n6', 'shared1'))
683 self.assertEqual(345, state2.get('n6', 'shared1'))
686 def test_shared_backing_file_propagates_state_to_has(self): argument
691 self.assertFalse(state1.has('n6', 'shared2'))
692 self.assertFalse(state2.has('n6', 'shared2'))
694 self.assertTrue(state1.has('n6', 'shared2'))
695 self.assertTrue(state2.has('n6', 'shared2'))
698 def test_shared_backing_file_propagates_state_from_discard(self): argument
704 self.assertEqual(10000, state1.get('n6', 'shared3'))
705 self.assertEqual(10000, state2.get('n6', 'shared3'))
707 self.assertRaises(KeyError, state1.get, 'n6', 'shared3')
708 self.assertRaises(KeyError, state2.get, 'n6', 'shared3')
711 def test_shared_backing_file_propagates_state_from_discard_namespace(self): argument
718 self.assertEqual(-1, state1.get('n7', 'shared4'))
719 self.assertEqual(-1, state2.get('n7', 'shared4'))
720 self.assertEqual(-2, state1.get('n7', 'shared5'))
721 self.assertEqual(-2, state2.get('n7', 'shared5'))
723 self.assertRaises(KeyError, state1.get, 'n7', 'shared4')
724 self.assertRaises(KeyError, state2.get, 'n7', 'shared4')
725 self.assertRaises(KeyError, state1.get, 'n7', 'shared5')
726 self.assertRaises(KeyError, state2.get, 'n7', 'shared5')
730 def setUp(self): argument
731 self.testdir = tempfile.mkdtemp(suffix='unittest')
732 self.original_wd = os.getcwd()
733 os.chdir(self.testdir)
737 ut_self = self
739 def read_from_file(self, file_path, merge=True): argument
740 if self._backing_file and file_path == self._backing_file:
741 ut_self.assertNotEqual(None, self._backing_file_lock)
742 return super(mocked_job_state, self).read_from_file(
744 def write_to_file(self, file_path): argument
745 if self._backing_file and file_path == self._backing_file:
746 ut_self.assertNotEqual(None, self._backing_file_lock)
747 return super(mocked_job_state, self).write_to_file(file_path)
748 self.state = mocked_job_state()
749 self.state.set_backing_file('backing_file')
752 def tearDown(self): argument
753 os.chdir(self.original_wd)
754 shutil.rmtree(self.testdir, ignore_errors=True)
757 def test_set(self): argument
758 self.state.set('ns1', 'var1', 100)
761 def test_get_missing(self): argument
762 self.assertRaises(KeyError, self.state.get, 'ns2', 'var2')
765 def test_get_present(self): argument
766 self.state.set('ns3', 'var3', 333)
767 self.assertEqual(333, self.state.get('ns3', 'var3'))
770 def test_set_backing_file(self): argument
771 self.state.set_backing_file('some_other_file')
774 def test_has_missing(self): argument
775 self.assertFalse(self.state.has('ns4', 'var4'))
778 def test_has_present(self): argument
779 self.state.set('ns5', 'var5', 55555)
780 self.assertTrue(self.state.has('ns5', 'var5'))
783 def test_discard_missing(self): argument
784 self.state.discard('ns6', 'var6')
787 def test_discard_present(self): argument
788 self.state.set('ns7', 'var7', -777)
789 self.state.discard('ns7', 'var7')
792 def test_discard_missing_namespace(self): argument
793 self.state.discard_namespace('ns8')
796 def test_discard_present_namespace(self): argument
797 self.state.set('ns8', 'var8', 80)
798 self.state.set('ns8', 'var8.1', 81)
799 self.state.discard_namespace('ns8')
802 def test_disable_backing_file(self): argument
803 self.state.set_backing_file(None)
806 def test_change_backing_file(self): argument
807 self.state.set_backing_file('another_backing_file')
810 def test_read_from_a_non_backing_file(self): argument
814 self.state.read_from_file('non_backing_file')
817 def test_write_to_a_non_backing_file(self): argument
818 self.state.write_to_file('non_backing_file')
822 def setUp(self): argument
825 self.job_class = job_stub
826 self.job = job_stub()
827 self.state = base_job.job_state()
828 self.job.stateobj = self.state
831 def test_properties_are_readwrite(self): argument
832 self.job_class.testprop1 = base_job.job_state.property_factory(
834 self.job.testprop1 = 'testvalue'
835 self.assertEqual('testvalue', self.job.testprop1)
838 def test_properties_use_default_if_not_initialized(self): argument
839 self.job_class.testprop2 = base_job.job_state.property_factory(
841 self.assertEqual('abc123', self.job.testprop2)
844 def test_properties_do_not_collisde(self): argument
845 self.job_class.testprop3 = base_job.job_state.property_factory(
847 self.job_class.testprop4 = base_job.job_state.property_factory(
849 self.job.testprop3 = 500
850 self.job.testprop4 = '1000'
851 self.assertEqual(500, self.job.testprop3)
852 self.assertEqual('1000', self.job.testprop4)
855 def test_properties_do_not_collide_across_different_state_objects(self): argument
856 self.job_class.testprop5 = base_job.job_state.property_factory(
858 self.job.auxstateobj = base_job.job_state()
859 self.job_class.auxtestprop5 = base_job.job_state.property_factory(
861 self.job.auxtestprop5 = 700
862 self.assertEqual(55, self.job.testprop5)
863 self.assertEqual(700, self.job.auxtestprop5)
866 def test_properties_do_not_collide_across_different_job_objects(self): argument
867 self.job_class.testprop6 = base_job.job_state.property_factory(
869 job1 = self.job
870 job2 = self.job_class()
873 self.assertEqual('notdefaultval', job1.testprop6)
874 self.assertEqual('defaultval', job2.testprop6)
876 self.assertEqual('notdefaultval', job1.testprop6)
877 self.assertEqual('job2val', job2.testprop6)
879 def test_properties_in_different_namespaces_do_not_collide(self): argument
880 self.job_class.ns1 = base_job.job_state.property_factory(
882 self.job_class.ns2 = base_job.job_state.property_factory(
884 self.assertEqual('default1', self.job.ns1)
885 self.assertEqual('default2', self.job.ns2)
886 self.job.ns1 = 'notdefault'
887 self.job.ns2 = 'alsonotdefault'
888 self.assertEqual('notdefault', self.job.ns1)
889 self.assertEqual('alsonotdefault', self.job.ns2)
893 def test_accepts_valid_status_code(self): argument
899 def test_accepts_valid_start_status_code(self): argument
903 def test_accepts_valid_end_status_code(self): argument
909 def test_rejects_invalid_status_code(self): argument
910 self.assertRaises(ValueError, base_job.status_log_entry,
914 def test_rejects_invalid_start_status_code(self): argument
915 self.assertRaises(ValueError, base_job.status_log_entry,
917 self.assertRaises(ValueError, base_job.status_log_entry,
919 self.assertRaises(ValueError, base_job.status_log_entry,
921 self.assertRaises(ValueError, base_job.status_log_entry,
925 def test_rejects_invalid_end_status_code(self): argument
926 self.assertRaises(ValueError, base_job.status_log_entry,
930 def test_accepts_valid_subdir(self): argument
935 def test_rejects_bad_subdir(self): argument
936 self.assertRaises(ValueError, base_job.status_log_entry,
938 self.assertRaises(ValueError, base_job.status_log_entry,
940 self.assertRaises(ValueError, base_job.status_log_entry,
942 self.assertRaises(ValueError, base_job.status_log_entry,
944 self.assertRaises(ValueError, base_job.status_log_entry,
948 def test_accepts_valid_operation(self): argument
953 def test_rejects_bad_operation(self): argument
954 self.assertRaises(ValueError, base_job.status_log_entry,
956 self.assertRaises(ValueError, base_job.status_log_entry,
958 self.assertRaises(ValueError, base_job.status_log_entry,
960 self.assertRaises(ValueError, base_job.status_log_entry,
962 self.assertRaises(ValueError, base_job.status_log_entry,
966 def test_simple_message(self): argument
971 def test_message_split_into_multiple_lines(self): argument
978 def test_message_with_tabs(self): argument
982 def test_message_with_custom_fields(self): argument
987 def assertRendered(self, rendered, status, subdir, operation, msg, argument
990 self.assertEqual(parts[0], status)
991 self.assertEqual(parts[1], subdir)
992 self.assertEqual(parts[2], operation)
993 self.assertEqual(parts[-1], msg)
995 self.assertEqual(int(fields['timestamp']), timestamp)
996 self.assert_('localtime' in fields) # too flaky to do an exact check
999 self.assertEqual(fields, extra_fields)
1002 def test_base_render(self): argument
1005 self.assertRendered(entry.render(), 'GOOD', '----', '----', 'message1',
1009 def test_subdir_render(self): argument
1012 self.assertRendered(entry.render(), 'FAIL', 'sub', '----', 'message2',
1016 def test_operation_render(self): argument
1019 self.assertRendered(entry.render(), 'ABORT', '----', 'myop', 'message3',
1023 def test_fields_render(self): argument
1027 self.assertRendered(entry.render(), 'WARN', '----', '----', 'message4',
1031 def assertEntryEqual(self, lhs, rhs): argument
1032 self.assertEqual(
1037 def test_base_parse(self): argument
1043 self.assertEntryEqual(entry, parsed_entry)
1046 def test_subdir_parse(self): argument
1052 self.assertEntryEqual(entry, parsed_entry)
1055 def test_operation_parse(self): argument
1061 self.assertEntryEqual(entry, parsed_entry)
1064 def test_extra_lines_parse(self): argument
1067 self.assertEqual(None, parsed_entry)
1071 def setUp(self): argument
1072 self.testdir = tempfile.mkdtemp(suffix='unittest')
1073 self.original_wd = os.getcwd()
1074 os.chdir(self.testdir)
1077 resultdir = self.testdir
1078 self.job = stub_job() # need to hold a reference to the job
1080 def __init__(self): argument
1081 self.indent = 0
1082 def increment(self): argument
1083 self.indent += 1
1084 def decrement(self): argument
1085 self.indent -= 1
1086 self.indenter = stub_indenter()
1087 self.logger = base_job.status_logger(self.job, self.indenter)
1090 def make_dummy_entry(self, rendered_text, start=False, end=False, argument
1110 def is_start(self): argument
1112 def is_end(self): argument
1114 def render(self): argument
1121 def test_render_includes_indent(self): argument
1122 entry = self.make_dummy_entry('LINE0')
1123 self.assertEqual('LINE0', self.logger.render_entry(entry))
1124 self.indenter.increment()
1125 self.indenter.increment()
1126 self.assertEqual('\t\tLINE0', self.logger.render_entry(entry))
1129 def test_render_handles_start(self): argument
1130 entry = self.make_dummy_entry('LINE10', start=True)
1131 self.indenter.increment()
1132 self.assertEqual('\tLINE10', self.logger.render_entry(entry))
1135 def test_render_handles_end(self): argument
1136 entry = self.make_dummy_entry('LINE20', end=True)
1137 self.indenter.increment()
1138 self.indenter.increment()
1139 self.indenter.increment()
1140 self.assertEqual('\t\tLINE20', self.logger.render_entry(entry))
1143 def test_writes_toplevel_log(self): argument
1144 entries = [self.make_dummy_entry('LINE%d' % x) for x in xrange(3)]
1146 self.logger.record_entry(entry)
1147 self.assertEqual('LINE0\nLINE1\nLINE2\n', open('status').read())
1150 def test_uses_given_filenames(self): argument
1152 self.logger = base_job.status_logger(self.job, self.indenter,
1155 self.logger.record_entry(self.make_dummy_entry('LINE1', subdir='sub'))
1156 self.logger.record_entry(self.make_dummy_entry('LINE2', subdir='sub'))
1157 self.logger.record_entry(self.make_dummy_entry('LINE3'))
1159 self.assertEqual('LINE1\nLINE2\nLINE3\n', open('global.log').read())
1160 self.assertEqual('LINE1\nLINE2\n', open('sub/subdir.log').read())
1162 self.assertFalse(os.path.exists('status'))
1163 self.assertFalse(os.path.exists('sub/status'))
1164 self.assertFalse(os.path.exists('subdir.log'))
1165 self.assertFalse(os.path.exists('sub/global.log'))
1168 def test_filenames_are_mutable(self): argument
1170 self.logger = base_job.status_logger(self.job, self.indenter,
1173 self.logger.record_entry(self.make_dummy_entry('LINE1', subdir='sub2'))
1174 self.logger.record_entry(self.make_dummy_entry('LINE2'))
1175 self.logger.global_filename = 'global.log2'
1176 self.logger.subdir_filename = 'subdir.log2'
1177 self.logger.record_entry(self.make_dummy_entry('LINE3', subdir='sub2'))
1178 self.logger.record_entry(self.make_dummy_entry('LINE4'))
1180 self.assertEqual('LINE1\nLINE2\n', open('global.log').read())
1181 self.assertEqual('LINE1\n', open('sub2/subdir.log').read())
1182 self.assertEqual('LINE3\nLINE4\n', open('global.log2').read())
1183 self.assertEqual('LINE3\n', open('sub2/subdir.log2').read())
1186 def test_writes_subdir_logs(self): argument
1189 self.logger.record_entry(self.make_dummy_entry('LINE1'))
1190 self.logger.record_entry(self.make_dummy_entry('LINE2', subdir='abc'))
1191 self.logger.record_entry(self.make_dummy_entry('LINE3', subdir='abc'))
1192 self.logger.record_entry(self.make_dummy_entry('LINE4', subdir='123'))
1194 self.assertEqual('LINE1\nLINE2\nLINE3\nLINE4\n', open('status').read())
1195 self.assertEqual('LINE2\nLINE3\n', open('abc/status').read())
1196 self.assertEqual('LINE4\n', open('123/status').read())
1199 def test_writes_no_subdir_when_disabled(self): argument
1201 self.logger.record_entry(self.make_dummy_entry('LINE1'))
1202 self.logger.record_entry(self.make_dummy_entry('LINE2', subdir='sub'))
1203 self.logger.record_entry(self.make_dummy_entry(
1205 self.logger.record_entry(self.make_dummy_entry('LINE4', subdir='sub'))
1207 self.assertEqual('LINE1\nLINE2\nLINE3\nLINE4\n', open('status').read())
1208 self.assertEqual('LINE2\nLINE4\n', open('sub/status').read())
1209 self.assert_(not os.path.exists('sub_nowrite/status'))
1212 def test_indentation(self): argument
1213 self.logger.record_entry(self.make_dummy_entry('LINE1', start=True))
1214 self.logger.record_entry(self.make_dummy_entry('LINE2'))
1215 self.logger.record_entry(self.make_dummy_entry('LINE3', start=True))
1216 self.logger.record_entry(self.make_dummy_entry('LINE4'))
1217 self.logger.record_entry(self.make_dummy_entry('LINE5'))
1218 self.logger.record_entry(self.make_dummy_entry('LINE6', end=True))
1219 self.logger.record_entry(self.make_dummy_entry('LINE7', end=True))
1220 self.logger.record_entry(self.make_dummy_entry('LINE8'))
1224 self.assertEqual(expected_log, open('status').read())
1227 def test_multiline_indent(self): argument
1228 self.logger.record_entry(self.make_dummy_entry('LINE1\n blah\n'))
1229 self.logger.record_entry(self.make_dummy_entry('LINE2', start=True))
1230 self.logger.record_entry(
1231 self.make_dummy_entry('LINE3\n blah\n two\n'))
1232 self.logger.record_entry(self.make_dummy_entry('LINE4', end=True))
1236 self.assertEqual(expected_log, open('status').read())
1239 def test_hook_is_called(self): argument
1240 entries = [self.make_dummy_entry('LINE%d' % x) for x in xrange(5)]
1244 self.logger = base_job.status_logger(self.job, self.indenter,
1247 self.logger.record_entry(entry)
1248 self.assertEqual(entries, recorded_entries)
1251 def tearDown(self): argument
1252 os.chdir(self.original_wd)
1253 shutil.rmtree(self.testdir, ignore_errors=True)
1257 def setUp(self): argument
1263 def _find_resultdir(self): argument
1265 self.job = stub_job()
1268 def test_default_with_no_args_means_no_tags(self): argument
1269 self.assertEqual(('testname', 'testname', ''),
1270 self.job._build_tagged_test_name('testname', {}))
1271 self.assertEqual(('othername', 'othername', ''),
1272 self.job._build_tagged_test_name('othername', {}))
1275 def test_tag_argument_appended(self): argument
1276 self.assertEqual(
1278 self.job._build_tagged_test_name('test1', {'tag': 'mytag'}))
1281 def test_turning_on_use_sequence_adds_sequence_tags(self): argument
1282 self.job.use_sequence_number = True
1283 self.assertEqual(
1285 self.job._build_tagged_test_name('test2', {}))
1286 self.assertEqual(
1288 self.job._build_tagged_test_name('test2', {}))
1289 self.assertEqual(
1291 self.job._build_tagged_test_name('test3', {}))
1294 def test_adding_automatic_test_tag_automatically_tags(self): argument
1295 self.job.automatic_test_tag = 'autotag'
1296 self.assertEqual(
1298 self.job._build_tagged_test_name('test4', {}))
1301 def test_none_automatic_test_tag_turns_off_tagging(self): argument
1302 self.job.automatic_test_tag = 'autotag'
1303 self.assertEqual(
1305 self.job._build_tagged_test_name('test5', {}))
1306 self.job.automatic_test_tag = None
1307 self.assertEqual(
1309 self.job._build_tagged_test_name('test5', {}))
1312 def test_empty_automatic_test_tag_turns_off_tagging(self): argument
1313 self.job.automatic_test_tag = 'autotag'
1314 self.assertEqual(
1316 self.job._build_tagged_test_name('test6', {}))
1317 self.job.automatic_test_tag = ''
1318 self.assertEqual(
1320 self.job._build_tagged_test_name('test6', {}))
1323 def test_subdir_tag_modifies_subdir_and_tag_only(self): argument
1324 self.assertEqual(
1326 self.job._build_tagged_test_name('test7',
1330 def test_all_tag_components_together(self): argument
1331 self.job.use_sequence_number = True
1332 self.job.automatic_test_tag = 'auto'
1336 actual = self.job._build_tagged_test_name(
1338 self.assertEqual(expected, actual)
1341 def test_subtest_with_master_test_path_and_subdir(self): argument
1342 self.assertEqual(
1344 self.job._build_tagged_test_name('test9',
1349 def test_subtest_all_tag_components_together_subdir(self): argument
1350 self.job.use_sequence_number = True
1351 self.job.automatic_test_tag = 'auto'
1355 actual = self.job._build_tagged_test_name(
1358 self.assertEqual(expected, actual)
1362 def setUp(self): argument
1363 self.resultdir = tempfile.mkdtemp(suffix='unittest')
1370 return self.resultdir
1374 self.job = stub_job()
1378 self.original_exception = logging.exception
1381 self.original_wd = os.getcwd()
1382 os.chdir(self.resultdir)
1385 def tearDown(self): argument
1386 logging.exception = self.original_exception
1387 os.chdir(self.original_wd)
1388 shutil.rmtree(self.resultdir, ignore_errors=True)
1391 def test_raises_test_error_if_outputdir_exists(self): argument
1393 self.assert_(os.path.exists('subdir1'))
1394 self.assertRaises(error.TestError, self.job._make_test_outputdir,
1398 def test_raises_test_error_if_outputdir_uncreatable(self): argument
1399 os.chmod(self.resultdir, stat.S_IRUSR | stat.S_IXUSR)
1400 self.assert_(not os.path.exists('subdir2'))
1401 self.assertRaises(OSError, os.mkdir, 'subdir2')
1402 self.assertRaises(error.TestError, self.job._make_test_outputdir,
1404 self.assert_(not os.path.exists('subdir2'))
1407 def test_creates_writable_directory(self): argument
1408 self.assert_(not os.path.exists('subdir3'))
1409 self.job._make_test_outputdir('subdir3')
1410 self.assert_(os.path.isdir('subdir3'))
1413 self.assert_(not os.path.exists('subdir3/testfile'))
1415 self.assert_(os.path.isfile('subdir3/testfile'))