Skip to content

Commit

Permalink
All test cases now inherit from drgn's TestCase
Browse files Browse the repository at this point in the history
The majority of test cases already inherited from drgn's
TestCase class. The few outliers that inherited directly
from unittest.TestCase have been brought in line with the
other tests.

Signed-off-by: Kevin Svetlitski <[email protected]>
  • Loading branch information
Svetlitski committed Jan 11, 2022
1 parent dfc8cb5 commit d79ee95
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 22 deletions.
3 changes: 2 additions & 1 deletion tests/helpers/linux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import unittest

import drgn
from tests import TestCase


class LinuxHelperTestCase(unittest.TestCase):
class LinuxHelperTestCase(TestCase):
prog = None
skip_reason = None

Expand Down
4 changes: 2 additions & 2 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: GPL-3.0-or-later

import pydoc
import unittest

import drgn
from tests import TestCase


class TestDocs(unittest.TestCase):
class TestDocs(TestCase):
def test_render(self):
pydoc.render_doc(drgn)
5 changes: 2 additions & 3 deletions tests/test_language_c.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: GPL-3.0-or-later

from functools import reduce
import operator
import unittest
Expand All @@ -15,7 +14,7 @@
cast,
container_of,
)
from tests import MockProgramTestCase
from tests import MockProgramTestCase, TestCase
from tests.libdrgn import C_TOKEN, Lexer, drgn_lexer_c


Expand Down Expand Up @@ -712,7 +711,7 @@ def test_function_no_name(self):
)


class TestLexer(unittest.TestCase):
class TestLexer(TestCase):
def lex(self, s):
lexer = Lexer(drgn_lexer_c, s)
while True:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_lexer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: GPL-3.0-or-later

import unittest

from tests import TestCase
from tests.libdrgn import Lexer, drgn_test_lexer_func


class TestLexer(unittest.TestCase):
class TestLexer(TestCase):
def test_pop(self):
lexer = Lexer(drgn_test_lexer_func, "12345")
for i in range(5):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_path.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: GPL-3.0-or-later

import itertools
import os.path
import unittest

from drgn import filename_matches
from tests import TestCase
from tests.libdrgn import PathIterator, path_ends_with


Expand Down Expand Up @@ -34,7 +34,7 @@ def join_combinations(components):
yield components


class TestPathIterator(unittest.TestCase):
class TestPathIterator(TestCase):
def assertComponents(self, path_components, expected, combinations=True):
if combinations:
cases = join_combinations(path_components)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_platform.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: GPL-3.0-or-later

import itertools
import unittest

from drgn import Architecture, Platform, PlatformFlags
from tests import TestCase


class TestPlatform(unittest.TestCase):
class TestPlatform(TestCase):
def test_default_flags(self):
Platform(Architecture.X86_64)
self.assertRaises(ValueError, Platform, Architecture.UNKNOWN)
Expand Down
3 changes: 1 addition & 2 deletions tests/test_program.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: GPL-3.0-or-later

import ctypes
import itertools
import os
Expand Down Expand Up @@ -39,7 +38,7 @@ def zero_memory_read(address, count, offset, physical):
return bytes(count)


class TestProgram(unittest.TestCase):
class TestProgram(TestCase):
def test_set_pid(self):
# Debug the running Python interpreter itself.
prog = Program()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_python.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: GPL-3.0-or-later

import unittest

import _drgn
import drgn
from tests import TestCase


class TestModule(unittest.TestCase):
class TestModule(TestCase):
def test_all(self):
# At least for now, everything in the Python library should go in
# __all__, so make sure that happens.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_serialize.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: GPL-3.0-or-later

import unittest

from tests import TestCase
from tests.libdrgn import deserialize_bits, serialize_bits

VALUE = 12345678912345678989
Expand Down Expand Up @@ -34,7 +34,7 @@ def py_serialize_bits(value, bit_offset, bit_size, little_endian):
return buf0, buf1


class TestSerialize(unittest.TestCase):
class TestSerialize(TestCase):
def test_deserialize(self):
for bit_size in range(1, 65):
expected = VALUE & ((1 << bit_size) - 1)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_symbol.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: GPL-3.0-or-later

import tempfile
from typing import NamedTuple
import unittest

from drgn import Program, SymbolBinding, SymbolKind
from tests import TestCase
from tests.dwarfwriter import dwarf_sections
from tests.elf import ET, PT, SHT, STB, STT
from tests.elfwriter import ElfSection, ElfSymbol, create_elf_file
Expand Down Expand Up @@ -56,7 +56,7 @@ class Symbol(NamedTuple):
kind: SymbolKind


class TestElfSymbol(unittest.TestCase):
class TestElfSymbol(TestCase):
def assert_symbol_equal(self, drgn_symbol, symbol):
self.assertEqual(
Symbol(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: GPL-3.0-or-later

from functools import cmp_to_key
import unittest

from tests import TestCase
from util import KernelVersion, verrevcmp


class TestUtil(unittest.TestCase):
class TestUtil(TestCase):
def assertVersionSort(self, sorted_list):
self.assertEqual(sorted(sorted_list, key=cmp_to_key(verrevcmp)), sorted_list)

Expand Down

0 comments on commit d79ee95

Please sign in to comment.