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

This commit is contained in:
rdb 2018-08-20 16:25:55 +02:00
parent 35fff81b6a
commit 4f9a2aca85
2 changed files with 35 additions and 20 deletions

View File

@ -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) path = core.Filename.from_os_specific(file.name)
yield 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) path = core.Filename.from_os_specific(file.name)
yield 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) path = core.Filename.from_os_specific(file.name)
yield file.name path.make_true_case()
write_image(path, 1)
yield path
file.close() file.close()

View File

@ -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): @pytest.fixture
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') file = tempfile.NamedTemporaryFile(suffix='.bin')
filename = core.Filename.from_os_specific(str(p)) 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') file = tempfile.NamedTemporaryFile(suffix='.bin')
filename = core.Filename.from_os_specific(str(p)) 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') file = tempfile.NamedTemporaryFile(suffix='.bin')
filename = core.Filename.from_os_specific(str(p)) 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: file.seek(0)
f.seek(0) file.write(b'\xFF\xFF\xFF\x4F')
f.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: file.truncate(size)
f.truncate(size)
dg2 = core.Datagram() dg2 = core.Datagram()
dif = core.DatagramInputFile() dif = core.DatagramInputFile()