Skip to content

chore: Added unit test and __repr__ for NftId class#1747

Draft
om12prakash wants to merge 4 commits intohiero-ledger:mainfrom
om12prakash:1538
Draft

chore: Added unit test and __repr__ for NftId class#1747
om12prakash wants to merge 4 commits intohiero-ledger:mainfrom
om12prakash:1538

Conversation

@om12prakash
Copy link
Contributor

Description:

Related issue(s):

Fixes #1627

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: om12prakash <ompyiiitg@gmail.com>
Signed-off-by: om12prakash <ompyiiitg@gmail.com>
Signed-off-by: om12prakash <ompyiiitg@gmail.com>
@github-actions
Copy link

github-actions bot commented Feb 7, 2026

Hi, this is MergeConflictBot.
Your pull request cannot be merged because it contains merge conflicts.

Please resolve these conflicts locally and push the changes.

Quick Fix for CHANGELOG.md Conflicts

If your conflict is only in CHANGELOG.md, you can resolve it easily using the GitHub web editor:

  1. Click on the "Resolve conflicts" button in the PR
  2. Accept both changes (keep both changelog entries)
  3. Click "Mark as resolved"
  4. Commit the merge

For all other merge conflicts, please read:

Thank you for contributing!

Signed-off-by: om12prakash <55754034+om12prakash@users.noreply.github.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2026

Walkthrough

Added a __repr__ method to the NftId class that returns a formatted string representation displaying token_id and serial_number. Includes a unit test validating the method's behavior and a changelog entry documenting the change.

Changes

Cohort / File(s) Summary
NftId repr Implementation
src/hiero_sdk_python/tokens/nft_id.py
Added __repr__(self) -> str method returning formatted string in the pattern NftId(token_id=X.X.X, serial_number=Y).
Unit Test for repr
tests/unit/test_nft_id_repr.py
New test file with single unit test verifying __repr__ output for NftId instance with token_id (0, 0, 123) and serial_number 5.
Changelog Entry
CHANGELOG.md
Added entry documenting the new __repr__ public method on NftId class.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a unit test and repr method for NftId class.
Description check ✅ Passed The description references issue #1627 which is related to implementing repr for NftId, and mentions adding a unit test and custom repr method.
Linked Issues check ✅ Passed The PR successfully implements the repr method for NftId returning 'NftId(token_id=0.0.123, serial_number=5)' format [#1627] and includes a unit test verifying the behavior [#1627].
Out of Scope Changes check ✅ Passed All changes are within scope: repr method addition to NftId class, corresponding unit test, and a CHANGELOG entry are all specified in issue #1627.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Comment on lines +107 to +109
def __repr__(self) -> str:

return f"NftId(token_id = {self.token_id}, serial_number = {self.serial_number})" No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

__repr__ format deviates from issue spec and Python convention.

Issue #1627 specifies the format as NftId(token_id=0.0.123, serial_number=5) (no spaces around =), and Python's convention for __repr__ is to mimic constructor-call syntax (PEP 257), which also omits spaces around = in keyword arguments. The current output has extra spaces.

Proposed fix
     def __repr__(self) -> str:
-    
-        return f"NftId(token_id = {self.token_id}, serial_number = {self.serial_number})"
+        return f"NftId(token_id={self.token_id}, serial_number={self.serial_number})"

Copy link
Contributor

@manishdait manishdait Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with this

Comment on lines +10 to +13
def test_nft_id_repr():
token_id = TokenId(0, 0, 123)
nft_id = NftId(token_id, 5)
assert repr(nft_id) == "NftId(token_id = 0.0.123, serial_number = 5)" No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Expand test coverage with edge cases and boundary conditions.

A single happy-path test is insufficient. Per coding guidelines: cover boundary conditions, verify return type, and test additional scenarios. Consider adding cases for serial_number=0 (boundary), different token_id values, and verifying repr returns a str.

Suggested additional tests
def test_nft_id_repr_zero_serial():
    token_id = TokenId(0, 0, 1)
    nft_id = NftId(token_id, 0)
    result = repr(nft_id)
    assert isinstance(result, str)
    assert "serial_number=0" in result

def test_nft_id_repr_large_values():
    token_id = TokenId(1, 2, 999999)
    nft_id = NftId(token_id, 2**53)
    result = repr(nft_id)
    assert "token_id=1.2.999999" in result
    assert f"serial_number={2**53}" in result

As per coding guidelines, "Unit tests should be extensive - test even if we don't expect users to use it currently. Cover happy paths AND unhappy paths/edge cases. Test boundary conditions, null/None values, empty collections, etc."

Copy link
Contributor

@manishdait manishdait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@om12prakash, Thanks for PR, I have added a change request, rest of the PR looks good.

pytestmark = pytest.mark.unit


def test_nft_id_repr():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be move to tests/unit/nft_id_test.py

@manishdait manishdait added the status: needs developer revision PR has requested changes that the developer needs to implement label Feb 7, 2026
@exploreriii exploreriii marked this pull request as draft February 7, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs developer revision PR has requested changes that the developer needs to implement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Beginner]: Implement __repr__ Method for NftId Class

2 participants