Skip to content

Commit c7db248

Browse files
committed
Increase test coverage in udf.py.
By adding a few more tests and fixing up tests that were incorrectly configured. Signed-off-by: Chris Lalancette <clalancette@gmail.com>
1 parent f3d6a42 commit c7db248

File tree

2 files changed

+159
-9
lines changed

2 files changed

+159
-9
lines changed

docs/design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ PyCdlib has an extensive test suite of hundreds of tests that get run on each re
3737
- In new integration tests, a new ISO is created using the PyCdlib [new](pycdlib-api.html#PyCdlib-new) method, and the ISO is manipulated in specific ways. Various aspects of these newly created files are compared against known examples to ensure that things were created as they should be.
3838
- In hybrid integration tests, specific sequences of files and directories are created, and then an ISO is generated using genisoimage from [cdrkit](https://launchpad.net/cdrkit). Then the PyCdlib [open](pycdlib-api.html#PyCdlib-open) method is used to open up the resulting file, and the ISO is manipulated in specific ways. Various aspects of these newly created files are compared against known examples to ensure that things were created as they should be.
3939

40-
PyCdlib currently has 96% code coverage from the tests, and anytime a new bug is found, a test is written to ensure that the bug can’t happen again.
40+
PyCdlib currently has 95% code coverage from the tests, and anytime a new bug is found, a test is written to ensure that the bug can’t happen again.
4141

4242
---
4343

tests/unit/test_udf.py

Lines changed: 158 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ def test_tag_eq():
349349

350350
assert(tag == tag2)
351351

352+
def test_tag_eq_not_same_object_type():
353+
tag = pycdlib.udf.UDFTag()
354+
tag.new(0, 0)
355+
356+
not_a_tag = object()
357+
358+
assert(tag != not_a_tag)
359+
352360
# Anchor
353361
def test_anchor_parse_initialized_twice():
354362
anchor = pycdlib.udf.UDFAnchorVolumeStructure()
@@ -384,6 +392,14 @@ def test_anchor_set_extent_location_not_initialized():
384392
anchor.set_extent_location(0, 0, 0)
385393
assert(str(excinfo.value) == 'UDF Anchor Volume Structure not initialized')
386394

395+
def test_anchor_eq_not_same_object_type():
396+
anchor = pycdlib.udf.UDFAnchorVolumeStructure()
397+
anchor.new()
398+
399+
not_an_anchor = object()
400+
401+
assert(anchor != not_an_anchor)
402+
387403
# Volume Descriptor Pointer
388404
def test_vdp_parse_initialized_twice():
389405
vdp = pycdlib.udf.UDFVolumeDescriptorPointer()
@@ -530,6 +546,14 @@ def test_timestamp_equal():
530546

531547
assert(ts == ts2)
532548

549+
def test_timestamp_eq_not_same_object_type():
550+
ts = pycdlib.udf.UDFTimestamp()
551+
ts.new(time.time())
552+
553+
not_a_ts = object()
554+
555+
assert(ts != not_a_ts)
556+
533557
# EntityID
534558
def test_entityid_parse_initialized_twice():
535559
entity = pycdlib.udf.UDFEntityID()
@@ -584,6 +608,14 @@ def test_entityid_equals():
584608

585609
assert(entity == entity2)
586610

611+
def test_entityid_eq_not_same_object_type():
612+
entity = pycdlib.udf.UDFEntityID()
613+
entity.new(0)
614+
615+
not_an_entity = object()
616+
617+
assert(entity != not_an_entity)
618+
587619
# Charspec
588620
def test_charspec_parse_initialized_twice():
589621
charspec = pycdlib.udf.UDFCharspec()
@@ -632,6 +664,14 @@ def test_charspec_equal():
632664

633665
assert(charspec == charspec2)
634666

667+
def test_charspec_eq_not_same_object_type():
668+
charspec = pycdlib.udf.UDFCharspec()
669+
charspec.new(0, b'\x00'*63)
670+
671+
not_a_charspec = object()
672+
673+
assert(charspec != not_a_charspec)
674+
635675
# ExtentAD
636676
def test_extentad_parse_initialized_twice():
637677
extentad = pycdlib.udf.UDFExtentAD()
@@ -674,6 +714,14 @@ def test_extentad_equals():
674714

675715
assert(extentad == extentad2)
676716

717+
def test_extentad_eq_not_same_object_type():
718+
extentad = pycdlib.udf.UDFExtentAD()
719+
extentad.new(0, 0)
720+
721+
not_an_extentad = object()
722+
723+
assert(extentad != not_an_extentad)
724+
677725
# PVD
678726
def test_pvd_parse_initialized_twice():
679727
pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
@@ -776,6 +824,14 @@ def test_pvd_equals():
776824

777825
assert(pvd == pvd2)
778826

827+
def test_pvd_eq_not_same_object_type():
828+
pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
829+
pvd.new()
830+
831+
not_a_pvd = object()
832+
833+
assert(pvd != not_a_pvd)
834+
779835
# Implementation Use Volume Descriptor Implementation Use
780836
def test_impl_use_impl_use_parse_initialized_twice():
781837
impl = pycdlib.udf.UDFImplementationUseVolumeDescriptorImplementationUse()
@@ -797,7 +853,7 @@ def test_impl_use_impl_use_new_initialized_twice():
797853
impl.new()
798854
assert(str(excinfo.value) == 'UDF Implementation Use Volume Descriptor Implementation Use field already initialized')
799855

800-
def test_impl_use_impl_use_new_equals():
856+
def test_impl_use_impl_use_equals():
801857
impl = pycdlib.udf.UDFImplementationUseVolumeDescriptorImplementationUse()
802858
impl.new()
803859

@@ -806,6 +862,14 @@ def test_impl_use_impl_use_new_equals():
806862

807863
assert(impl == impl2)
808864

865+
def test_impl_use_impl_use_eq_not_same_object_type():
866+
impl = pycdlib.udf.UDFImplementationUseVolumeDescriptorImplementationUse()
867+
impl.new()
868+
869+
not_an_impl = object()
870+
871+
assert(impl != not_an_impl)
872+
809873
# Implementation Use
810874
def test_impl_use_parse_initialized_twice():
811875
impl = pycdlib.udf.UDFImplementationUseVolumeDescriptor()
@@ -858,6 +922,14 @@ def test_impl_use_equals():
858922

859923
assert(impl == impl2)
860924

925+
def test_impl_use_eq_not_same_object_type():
926+
impl = pycdlib.udf.UDFImplementationUseVolumeDescriptor()
927+
impl.new()
928+
929+
not_an_impl = object()
930+
931+
assert(impl != not_an_impl)
932+
861933
# Partition Header Descriptor
862934
def test_part_header_parse_initialized_twice():
863935
header = pycdlib.udf.UDFPartitionHeaderDescriptor()
@@ -888,6 +960,14 @@ def test_part_header_equals():
888960

889961
assert(header == header2)
890962

963+
def test_part_header_eq_not_same_object_type():
964+
header = pycdlib.udf.UDFPartitionHeaderDescriptor()
965+
header.new()
966+
967+
not_a_header = object()
968+
969+
assert(header != not_a_header)
970+
891971
# Partition Volume
892972
def test_part_parse_initialized_twice():
893973
part = pycdlib.udf.UDFPartitionVolumeDescriptor()
@@ -973,6 +1053,14 @@ def test_part_equals():
9731053

9741054
assert(part == part2)
9751055

1056+
def test_part_eq_not_same_object_type():
1057+
part = pycdlib.udf.UDFPartitionVolumeDescriptor()
1058+
part.new(3)
1059+
1060+
not_a_part = object()
1061+
1062+
assert(part != not_a_part)
1063+
9761064
# Type 0 Partition Map
9771065
def test_type_zero_part_map_parse_initialized_twice():
9781066
partmap = pycdlib.udf.UDFType0PartitionMap()
@@ -1180,6 +1268,14 @@ def test_shortad_set_extent_location():
11801268
ad.set_extent_location(0, 1)
11811269
assert(ad.log_block_num == 1)
11821270

1271+
def test_shortad_eq_not_same_object_type():
1272+
ad = pycdlib.udf.UDFShortAD()
1273+
ad.new(0)
1274+
1275+
not_an_ad = object()
1276+
1277+
assert(ad != not_an_ad)
1278+
11831279
# Long AD
11841280
def test_longad_parse_initialized_twice():
11851281
ad = pycdlib.udf.UDFLongAD()
@@ -1220,6 +1316,14 @@ def test_longad_equals():
12201316

12211317
assert(ad == ad2)
12221318

1319+
def test_longad_eq_not_same_object_type():
1320+
ad = pycdlib.udf.UDFLongAD()
1321+
ad.new(0, 0)
1322+
1323+
not_an_ad = object()
1324+
1325+
assert(ad != not_an_ad)
1326+
12231327
# Inline AD
12241328
def test_inlinead_parse_initialized_twice():
12251329
ad = pycdlib.udf.UDFInlineAD()
@@ -1417,6 +1521,14 @@ def test_logvoldesc_equals():
14171521

14181522
assert(logvol == logvol2)
14191523

1524+
def test_logvoldesc_eq_not_same_object_type():
1525+
logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
1526+
logvol.new()
1527+
1528+
not_a_logvol = object()
1529+
1530+
assert(logvol != not_a_logvol)
1531+
14201532
# Unallocated Space
14211533
def test_unallocated_parse_initialized_twice():
14221534
un = pycdlib.udf.UDFUnallocatedSpaceDescriptor()
@@ -1483,6 +1595,14 @@ def test_unallocated_equals():
14831595

14841596
assert(un == un2)
14851597

1598+
def test_unallocated_eq_not_same_object_type():
1599+
un = pycdlib.udf.UDFUnallocatedSpaceDescriptor()
1600+
un.new()
1601+
1602+
not_a_un = object()
1603+
1604+
assert(un != not_a_un)
1605+
14861606
# Terminating Descriptor
14871607
def test_terminating_parse_initialized_twice():
14881608
term = pycdlib.udf.UDFTerminatingDescriptor()
@@ -1742,6 +1862,18 @@ def test_icbtag_new_bad_file_type():
17421862
icb.new('foo')
17431863
assert(str(excinfo.value) == "Invalid file type for ICB; must be one of 'dir', 'file', or 'symlink'")
17441864

1865+
def test_icbtag_parse_bad_strategy_type():
1866+
icb = pycdlib.udf.UDFICBTag()
1867+
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
1868+
icb.parse(b'\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
1869+
assert(str(excinfo.value) == 'UDF ICB Tag invalid strategy type')
1870+
1871+
def test_icbtag_parse_bad_reserved():
1872+
icb = pycdlib.udf.UDFICBTag()
1873+
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
1874+
icb.parse(b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00')
1875+
assert(str(excinfo.value) == 'UDF ICB Tag reserved not 0')
1876+
17451877
# File Entry
17461878
def test_file_entry_parse_initialized_twice():
17471879
entry = pycdlib.udf.UDFFileEntry()
@@ -2088,7 +2220,25 @@ def test_file_ident_equals_other_parent():
20882220
fi2 = pycdlib.udf.UDFFileIdentifierDescriptor()
20892221
fi2.new(False, False, b'bar', None)
20902222

2091-
assert(not fi == fi2)
2223+
assert(fi != fi2)
2224+
2225+
def test_file_ident_eq_not_same_object_type():
2226+
fi = pycdlib.udf.UDFFileIdentifierDescriptor()
2227+
fi.new(False, True, b'foo', None)
2228+
2229+
not_an_fi = object()
2230+
2231+
assert(fi != not_an_fi)
2232+
2233+
def test_file_ident_eq_not_other_parent():
2234+
fi = pycdlib.udf.UDFFileIdentifierDescriptor()
2235+
# isdir, isparent, name, parent
2236+
fi.new(False, False, b'foo', None)
2237+
2238+
fi2 = pycdlib.udf.UDFFileIdentifierDescriptor()
2239+
fi2.new(False, True, b'bar', None)
2240+
2241+
assert(fi != fi2)
20922242

20932243
# Space Bitmap
20942244
def test_space_bitmap_parse_initialized_twice():
@@ -2296,7 +2446,7 @@ def test_indirect_new():
22962446
assert(indirect.desc_tag.tag_ident == 259)
22972447

22982448
# Terminating
2299-
def test_terminating_parse_initialized_twice():
2449+
def test_terminal_entry_parse_initialized_twice():
23002450
tag = pycdlib.udf.UDFTag()
23012451
tag.new(0, 0)
23022452

@@ -2306,36 +2456,36 @@ def test_terminating_parse_initialized_twice():
23062456
term.parse(b'\x00'*16 + b'\x00'*20, tag)
23072457
assert(str(excinfo.value) == 'UDF Terminal Entry already initialized')
23082458

2309-
def test_terminating_parse():
2459+
def test_terminal_entry_parse():
23102460
tag = pycdlib.udf.UDFTag()
23112461
tag.new(0, 0)
23122462

23132463
term = pycdlib.udf.UDFTerminalEntry()
23142464
term.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', tag)
23152465
assert(term.desc_tag.tag_ident == 0)
23162466

2317-
def test_terminating_record_not_initialized():
2467+
def test_terminal_entry_record_not_initialized():
23182468
term = pycdlib.udf.UDFTerminalEntry()
23192469
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
23202470
term.record()
23212471
assert(str(excinfo.value) == 'UDF Terminal Entry not initialized')
23222472

2323-
def test_terminating_record():
2473+
def test_terminal_entry_record():
23242474
tag = pycdlib.udf.UDFTag()
23252475
tag.new(0, 0)
23262476

23272477
term = pycdlib.udf.UDFTerminalEntry()
23282478
term.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', tag)
23292479
assert(term.record() == b'\x00\x00\x02\x00\x68\x00\x00\x00\xd2\x80\x14\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
23302480

2331-
def test_terminating_new_initialized_twice():
2481+
def test_terminal_entry_new_initialized_twice():
23322482
term = pycdlib.udf.UDFTerminalEntry()
23332483
term.new('dir')
23342484
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
23352485
term.new('dir')
23362486
assert(str(excinfo.value) == 'UDF Terminal Entry already initialized')
23372487

2338-
def test_terminating_new():
2488+
def test_terminal_entry_new():
23392489
term = pycdlib.udf.UDFTerminalEntry()
23402490
term.new('dir')
23412491
assert(term.desc_tag.tag_ident == 260)

0 commit comments

Comments
 (0)