pydumpling icon indicating copy to clipboard operation
pydumpling copied to clipboard

test: Add unit test for pydumpling/fake_types.py

Open gru-agent[bot] opened this issue 10 months ago • 0 comments

Trigger Info

Trigger Type Triggered By Source File Assignment
Manual cocolato pydumpling/fake_types.py Detail

Summary

This PR introduces a comprehensive suite of unit tests for the FakeType, FakeTraceback, FakeFrame, FakeClass, and FakeCode classes in the pydumpling.fake_types module. The tests ensure the correctness of the functionality and behavior of these classes, including their initialization, attribute handling, and utility methods.

Key Changes:

  • Test Coverage for FakeTraceback:

    • Tests for initialization with and without a mock traceback object.

    • Validation of attributes like tb_frame, tb_lineno, tb_next, and tb_lasti.

  • Test Coverage for FakeFrame:

    • Tests for initialization with a mock frame object.

    • Validation of attributes like f_code, f_globals, f_lineno, f_back, f_lasti, and f_builtins.

  • Test Coverage for FakeCode:

    • Tests for initialization with a mock code object.

    • Validation of attributes like co_filename, co_name, co_argcount, co_consts, co_firstlineno, co_lnotab, co_varnames, co_flags, and co_code.

    • Tests for handling co_lines, co_kwonlyargcount, and co_positions.

  • Utility Method Tests:

    • _safe_repr: Ensures safe handling of objects that raise exceptions in their __repr__ method.

    • _convert: Tests for converting various types of objects, including sequences and dictionaries.

    • _convert_dict: Tests for converting dictionaries with simple and complex keys.

Fixtures:

  • Added reusable pytest fixtures for mock traceback, frame, and code objects to streamline test setup.

These tests enhance the reliability of the pydumpling.fake_types module by verifying its behavior under various scenarios and edge cases.

[!TIP] You can @gru-agent and leave your feedback. TestGru will make adjustments based on your input

[!TIP] You can @gru-agent rebase to rebase the PR.

[!TIP] You can @gru-agent redo to reset or rebase before redoing the PR.

[!TIP] To modify the test code yourself, click here Edit Test Code

gru-agent[bot] avatar Feb 26 '25 11:02 gru-agent[bot]