Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unittest to test_datalab.py #946

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

01PrathamS
Copy link
Contributor

Summary

🎯 Purpose: Add unit test to test_datalab.py file
1. datalab.issues solely contains numeric and boolean values.
2. datalab.issue_summary solely contains numeric value

Links to Relevant Issues or Conversations

Resolves #937

Copy link

codecov bot commented Jan 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (23af72a) 96.83% compared to head (bf463ba) 96.81%.
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #946      +/-   ##
==========================================
- Coverage   96.83%   96.81%   -0.03%     
==========================================
  Files          71       71              
  Lines        5692     5708      +16     
  Branches      970      972       +2     
==========================================
+ Hits         5512     5526      +14     
- Misses         94       95       +1     
- Partials       86       87       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@01PrathamS 01PrathamS changed the title Add unittest to test_datalab.py file solves #937 Add unittest to test_datalab.py Jan 7, 2024
@elisno
Copy link
Member

elisno commented Jan 8, 2024

Hi @01PrathamS, thanks for the PR.

Unfortunately, the tests added are flawed. They're directly testing the mocked fields, which defeats the whole purpose of mocking for running tests.

Please take a moment to review the work more critically before submission. It's important to not only address the issue at hand but also to consider how the contribution genuinely enhances the project.
Ask yourself if the test being added provides meaningful validation or if it could be refined for greater impact.

@01PrathamS
Copy link
Contributor Author

hey @elisno thank you for your review, i realize my mistake and after that i read docs, and practice exercises.

can you please review my intuition if i'm not overlooking something. If you feel i'm not understanding things please point me towards documentation, i'm looking forward to your suggestions.

I'm writing this test function under test_datalab.py::TestDatalab

def test_get_issues_contains_bool_or_num(self, lab, monkeypatch):
    mock_issues: pd.DataFrame = pd.DataFrame(
        {
            "is_label_issue": [True, False, False, True, False],
            "label_score": [0.2, 0.4, 0.6, 0.1, 0.8],
            "is_near_duplicate_issue": [False, True, True, False, True],
            "near_duplicate_score": [0.5, 0.3, 0.1, 0.7, 0.2],
            "is_class_imbalance_issue": [False, False, False, False, True],
            "class_imbalance_score": [1.0, 1.0, 1.0, 1.0, 0.2],
        },
    )
    monkeypatch.setattr(lab, "issues", mock_issues)

    lab_issues = lab.get_issues()

    for col in lab_issues.columns: 
        assert lab_issues[col].dtype.kind in ['b', 'i', 'u', 'f'], f"Column {col} contains non-numeric/non-boolean values."
def test_get_issue_summary_contains_num(self, lab, monkeypatch):
    ## first column of the issue be issue name
    mock_summary: pd.DataFrame = pd.DataFrame(
        {
            "issue_type": ["label", "outlier"],
            "score": [0.5, 0.3],
            "num_issues": [1, 2],
        }
    )
    monkeypatch.setattr(lab, "issue_summary", mock_summary)

    lab_issue_summary = lab.get_issue_summary()

    for col in lab_issue_summary.columns[1:]: 
        assert lab_issue_summary[col].dtype.kind in ['i', 'u', 'f'], f"Column {col} contains non-numeric/non-boolean values."
    ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add a unit test that datalab.issues solely contains numeric and boolean values
2 participants