Skip to content

Creating a 🐍📦 with tests #26

@dpshelio

Description

@dpshelio

Help Charlene to test her package (#25) (remember to commit after each step, if appropriate).

  1. Choose who in your team is writing now! (make sure you've pulled the latest changes from your team's fork.)

  2. Create a tests directory inside sagittal_average so it looks like

    Desktop/ # if you cloned it there
    └── sagittal_average/
        ├── .git/
        ├── pyproject.toml
        ├── sagittal_average/
        └── tests/
    
  3. Add a test to avoid the confusion between rows and columns

    TEST_DIR = Path(__file__).parent   
    
    def test_average():
        # Creates input file
        data_input = np.zeros((20, 20))
        data_input[-1, :] = 1
        # The expeted result is all zeros, except the last one, it should be 1
        expected = np.zeros(20)
        expected[-1] = 1
    
        np.savetxt(TEST_DIR / "brain_sample.csv", data_input, fmt='%d', delimiter=',')
    
        # run python program
        run_averages(file_input=TEST_DIR / "brain_sample.csv",
                     file_output=TEST_DIR / "brain_average.csv")
    
        # Check result
        result = np.loadtxt(TEST_DIR / "brain_average.csv",  delimiter=',')
        np.testing.assert_array_equal(result, expected)   
  4. Fix sagittal_brain.py (the code wrongly averages over the columns, not the rows), make sure the test passes and commit these changes.

  5. Try to install it by running pip install -e . where the pyproject.toml is, and then run the tests with pytest.

  6. Share your solution as a pull request to Charlene's repository mentioning this issue (by including the text Addresses UCL-ARC-RSEworkshop-summer-25/RSE-Classwork#26 in the pull request description), remember to mention your team members too! (with @github_username)


Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions