From 339e1ce4d861d15084fd7f099d84a8ec7ba3dd88 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Sat, 26 May 2018 18:33:05 -0600 Subject: [PATCH] tests: Update the datagram tests --- tests/putil/test_datagram.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/putil/test_datagram.py b/tests/putil/test_datagram.py index 1349bd5656..47b1432368 100644 --- a/tests/putil/test_datagram.py +++ b/tests/putil/test_datagram.py @@ -96,6 +96,24 @@ def test_iterator(datagram_small): dgi = core.DatagramIterator(dg) verify(dgi) +# This tests the copy constructor: +@pytest.mark.xfail +def test_copy(datagram_small): + dg, verify = datagram_small + + dg2 = core.Datagram(dg) + dgi = core.DatagramIterator(dg2) + verify(dgi) + +@pytest.mark.xfail +def test_assign(datagram_small): + dg, verify = datagram_small + + dg2 = core.Datagram() + dg2.assign(dg) + dgi = core.DatagramIterator(dg2) + verify(dgi) + # These test DatagramInputFile/DatagramOutputFile: @@ -147,10 +165,10 @@ def test_file_corrupt(datagram_small, tmpdir): dof.put_datagram(dg) dof.close() - # Corrupt the size header to 4GB - with p.open(mode='wb') as f: + # Corrupt the size header to 1GB + with p.open(mode='r+b') as f: f.seek(0) - f.write(b'\xFF\xFF\xFF\xFF') + f.write(b'\xFF\xFF\xFF\x4F') dg2 = core.Datagram() dif = core.DatagramInputFile() @@ -158,4 +176,15 @@ def test_file_corrupt(datagram_small, tmpdir): assert not dif.get_datagram(dg2) dif.close() + # Truncate the file + for size in [12, 8, 4, 3, 2, 1, 0]: + with p.open(mode='r+b') as f: + f.truncate(size) + + dg2 = core.Datagram() + dif = core.DatagramInputFile() + dif.open(filename) + assert not dif.get_datagram(dg2) + dif.close() + # Should we test that dg2 is unmodified?