From 92f420974a594ecc6ab4334b5f3139282b55104a Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Sat, 7 Mar 2020 05:42:21 -0800 Subject: [PATCH] Reformat comments and a bit of test logic --- elftools/elf/dynamic.py | 22 ++++++++++++++++------ test/test_dbgfile.py | 19 +++++++------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/elftools/elf/dynamic.py b/elftools/elf/dynamic.py index 5a7c99c..a445ae9 100644 --- a/elftools/elf/dynamic.py +++ b/elftools/elf/dynamic.py @@ -75,12 +75,22 @@ class Dynamic(object): """ def __init__(self, stream, elffile, stringtable, position, empty): """ - :param stream: The file-like object from which to load data - :param elffile: The parent elffile object - :param stringtable: A stringtable reference to use for parsing string references in entries - :param position: The file offset of the dynamic segment/section - :param empty: Whether this is a degenerate case with zero entries. Normally, every dynamic table - will have at least one entry, the DT_NULL terminator. + stream: + The file-like object from which to load data + + elffile: + The parent elffile object + + stringtable: + A stringtable reference to use for parsing string references in + entries + + position: + The file offset of the dynamic segment/section + + empty: + Whether this is a degenerate case with zero entries. Normally, every + dynamic table will have at least one entry, the DT_NULL terminator. """ self.elffile = elffile self.elfstructs = elffile.structs diff --git a/test/test_dbgfile.py b/test/test_dbgfile.py index bd5f06e..901a19f 100644 --- a/test/test_dbgfile.py +++ b/test/test_dbgfile.py @@ -9,8 +9,7 @@ from elftools.dwarf.callframe import ZERO class TestDBGFile(unittest.TestCase): def test_dynamic_segment(self): - """ - Test that the degenerate case for the dynamic segment does not crash + """ Test that the degenerate case for the dynamic segment does not crash """ with open(os.path.join('test', 'testfiles_for_unittests', 'debug_info.elf'), 'rb') as f: @@ -18,18 +17,15 @@ class TestDBGFile(unittest.TestCase): seen_dynamic_segment = False for segment in elf.iter_segments(): - if segment.header.p_type != 'PT_DYNAMIC': - continue - - self.assertEqual(segment.num_tags(), 0, "The dynamic segment in this file should be empty") - seen_dynamic_segment = True - break + if segment.header.p_type == 'PT_DYNAMIC': + self.assertEqual(segment.num_tags(), 0, "The dynamic segment in this file should be empty") + seen_dynamic_segment = True + break self.assertTrue(seen_dynamic_segment, "There should be a dynamic segment in this file") def test_dynamic_section(self): - """ - Test that the degenerate case for the dynamic section does not crash + """ Test that the degenerate case for the dynamic section does not crash """ with open(os.path.join('test', 'testfiles_for_unittests', 'debug_info.elf'), 'rb') as f: @@ -39,8 +35,7 @@ class TestDBGFile(unittest.TestCase): self.assertEqual(section.num_tags(), 0, "The dynamic section in this file should be empty") def test_eh_frame(self): - """ - Test that parsing .eh_frame with SHT_NOBITS does not crash + """ Test that parsing .eh_frame with SHT_NOBITS does not crash """ with open(os.path.join('test', 'testfiles_for_unittests', 'debug_info.elf'), 'rb') as f: -- 2.30.2