]> granicus.if.org Git - python/commitdiff
#15872: Some more Windows related tuning to shutil.rmtree tests
authorHynek Schlawack <hs@ox.cx>
Mon, 10 Dec 2012 15:33:41 +0000 (16:33 +0100)
committerHynek Schlawack <hs@ox.cx>
Mon, 10 Dec 2012 15:33:41 +0000 (16:33 +0100)
Turns out, the snakebite bots behave also their peculiarities.

I'm really not proud of this stream of commits. :(

1  2 
Lib/test/test_shutil.py

index e0ecbf7601d459384c1e909f3113aaf16ce89018,a9b4676dfff3bd6b38255986e18110eaaf29dfad..01b93fc441125cb66484af9c75d03eb052a16368
@@@ -167,15 -128,14 +167,14 @@@ class TestShutil(unittest.TestCase)
  
          # existing file
          tmpdir = self.mkdtemp()
 -        self.write_file((tmpdir, "tstfile"), "")
 +        write_file((tmpdir, "tstfile"), "")
          filename = os.path.join(tmpdir, "tstfile")
 -        with self.assertRaises(OSError) as cm:
 +        with self.assertRaises(NotADirectoryError) as cm:
              shutil.rmtree(filename)
-         if cm.exception.filename.endswith('*.*'):
-             rm_name = os.path.join(filename, '*.*')
-         else:
-             rm_name = filename
-         self.assertEqual(cm.exception.filename, rm_name)
+         # The reason for this rather odd construct is that Windows sprinkles
+         # a \*.* at the end of file names. But only sometimes on some buildbots
+         possible_args = [filename, os.path.join(filename, '*.*')]
+         self.assertIn(cm.exception.filename, possible_args)
          self.assertTrue(os.path.exists(filename))
          # test that ignore_errors option is honored
          shutil.rmtree(filename, ignore_errors=True)
          self.assertEqual(len(errors), 2)
          self.assertIs(errors[0][0], os.listdir)
          self.assertEqual(errors[0][1], filename)
 -        self.assertIsInstance(errors[0][2][1], OSError)
 +        self.assertIsInstance(errors[0][2][1], NotADirectoryError)
-         self.assertEqual(errors[0][2][1].filename, rm_name)
+         self.assertIn(errors[0][2][1].filename, possible_args)
          self.assertIs(errors[1][0], os.rmdir)
          self.assertEqual(errors[1][1], filename)
 -        self.assertIsInstance(errors[1][2][1], OSError)
 +        self.assertIsInstance(errors[1][2][1], NotADirectoryError)
-         self.assertEqual(errors[1][2][1].filename, rm_name)
+         self.assertIn(errors[1][2][1].filename, possible_args)
 +
      # See bug #1071513 for why we don't run this on cygwin
      # and bug #1076467 for why we don't run this as root.
      if (hasattr(os, 'chmod') and sys.platform[:6] != 'cygwin'