Browse Source

tests: fix issues with temp files without correct case on Windows

rdb 7 years ago
parent
commit
4f9a2aca85
2 changed files with 35 additions and 20 deletions
  1. 12 6
      tests/gobj/test_texture_pool.py
  2. 23 14
      tests/putil/test_datagram.py

+ 12 - 6
tests/gobj/test_texture_pool.py

@@ -22,8 +22,10 @@ def image_rgb_path():
     "Generates an RGB image."
     "Generates an RGB image."
 
 
     file = tempfile.NamedTemporaryFile(suffix='-rgb.png')
     file = tempfile.NamedTemporaryFile(suffix='-rgb.png')
-    write_image(file.name, 3)
-    yield file.name
+    path = core.Filename.from_os_specific(file.name)
+    path.make_true_case()
+    write_image(path, 3)
+    yield path
     file.close()
     file.close()
 
 
 
 
@@ -32,8 +34,10 @@ def image_rgba_path():
     "Generates an RGBA image."
     "Generates an RGBA image."
 
 
     file = tempfile.NamedTemporaryFile(suffix='-rgba.png')
     file = tempfile.NamedTemporaryFile(suffix='-rgba.png')
-    write_image(file.name, 4)
-    yield file.name
+    path = core.Filename.from_os_specific(file.name)
+    path.make_true_case()
+    write_image(path, 4)
+    yield path
     file.close()
     file.close()
 
 
 
 
@@ -42,8 +46,10 @@ def image_gray_path():
     "Generates a grayscale image."
     "Generates a grayscale image."
 
 
     file = tempfile.NamedTemporaryFile(suffix='-gray.png')
     file = tempfile.NamedTemporaryFile(suffix='-gray.png')
-    write_image(file.name, 1)
-    yield file.name
+    path = core.Filename.from_os_specific(file.name)
+    path.make_true_case()
+    write_image(path, 1)
+    yield path
     file.close()
     file.close()
 
 
 
 

+ 23 - 14
tests/putil/test_datagram.py

@@ -1,6 +1,7 @@
 import pytest
 import pytest
 from panda3d import core
 from panda3d import core
 import sys
 import sys
+import tempfile
 
 
 # Fixtures for generating interesting datagrams (and verification functions) on
 # Fixtures for generating interesting datagrams (and verification functions) on
 # the fly...
 # the fly...
@@ -147,30 +148,39 @@ def do_file_test(dg, verify, filename):
     dgi = core.DatagramIterator(dg2)
     dgi = core.DatagramIterator(dg2)
     verify(dgi)
     verify(dgi)
 
 
-def test_file_small(datagram_small, tmpdir):
[email protected]
+def tmpfile():
+    file = tempfile.NamedTemporaryFile(suffix='.bin')
+    yield file
+    file.close()
+
+def test_file_small(datagram_small, tmpfile):
     """This tests DatagramOutputFile/DatagramInputFile on small datagrams."""
     """This tests DatagramOutputFile/DatagramInputFile on small datagrams."""
     dg, verify = datagram_small
     dg, verify = datagram_small
 
 
-    p = tmpdir.join('datagram.bin')
-    filename = core.Filename.from_os_specific(str(p))
+    file = tempfile.NamedTemporaryFile(suffix='.bin')
+    filename = core.Filename.from_os_specific(file.name)
+    filename.make_true_case()
 
 
     do_file_test(dg, verify, filename)
     do_file_test(dg, verify, filename)
 
 
-def test_file_large(datagram_large, tmpdir):
+def test_file_large(datagram_large, tmpfile):
     """This tests DatagramOutputFile/DatagramInputFile on very large datagrams."""
     """This tests DatagramOutputFile/DatagramInputFile on very large datagrams."""
     dg, verify = datagram_large
     dg, verify = datagram_large
 
 
-    p = tmpdir.join('datagram.bin')
-    filename = core.Filename.from_os_specific(str(p))
+    file = tempfile.NamedTemporaryFile(suffix='.bin')
+    filename = core.Filename.from_os_specific(file.name)
+    filename.make_true_case()
 
 
     do_file_test(dg, verify, filename)
     do_file_test(dg, verify, filename)
 
 
-def test_file_corrupt(datagram_small, tmpdir):
+def test_file_corrupt(datagram_small, tmpfile):
     """This tests DatagramInputFile's handling of a corrupt size header."""
     """This tests DatagramInputFile's handling of a corrupt size header."""
     dg, verify = datagram_small
     dg, verify = datagram_small
 
 
-    p = tmpdir.join('datagram.bin')
-    filename = core.Filename.from_os_specific(str(p))
+    file = tempfile.NamedTemporaryFile(suffix='.bin')
+    filename = core.Filename.from_os_specific(file.name)
+    filename.make_true_case()
 
 
     dof = core.DatagramOutputFile()
     dof = core.DatagramOutputFile()
     dof.open(filename)
     dof.open(filename)
@@ -178,9 +188,9 @@ def test_file_corrupt(datagram_small, tmpdir):
     dof.close()
     dof.close()
 
 
     # Corrupt the size header to 1GB
     # Corrupt the size header to 1GB
-    with p.open(mode='r+b') as f:
-        f.seek(0)
-        f.write(b'\xFF\xFF\xFF\x4F')
+    file.seek(0)
+    file.write(b'\xFF\xFF\xFF\x4F')
+    file.flush()
 
 
     dg2 = core.Datagram()
     dg2 = core.Datagram()
     dif = core.DatagramInputFile()
     dif = core.DatagramInputFile()
@@ -190,8 +200,7 @@ def test_file_corrupt(datagram_small, tmpdir):
 
 
     # Truncate the file
     # Truncate the file
     for size in [12, 8, 4, 3, 2, 1, 0]:
     for size in [12, 8, 4, 3, 2, 1, 0]:
-        with p.open(mode='r+b') as f:
-            f.truncate(size)
+        file.truncate(size)
 
 
         dg2 = core.Datagram()
         dg2 = core.Datagram()
         dif = core.DatagramInputFile()
         dif = core.DatagramInputFile()