Skip to content

Creating a 🐍📦 with tests #37

@dpshelio

Description

@dpshelio

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

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

  2. Create a tests directory inside sagittal_average and add a test similar to what we used last week when we discovered the bug.

    Hint

    You need a test_something function that runs all the below

    1. Create an input dataset
      data_input = np.zeros((20, 20))
      data_input[-1, :] = 1
    2. Save it into a file
      np.savetxt("brain_sample.csv", data_input, fmt='%d', delimiter=',')
    3. Create an array with expected result
      # The expeted result is all zeros, except the last one, it should be 1
      expected = np.zeros(20)
      expected[-1] = 1
    4. call the function with the files
      run_averages(file_input="brain_sample.csv",
                   file_output="brain_average.csv")
    5. Load the result
      result = np.loadtxt(TEST_DIR / "brain_average.csv",  delimiter=',')
    6. Compare the result with the expected values
      np.testing.assert_array_equal(result, expected)

    What could you do to make sure that these files we are creating don't interfere with our repository or the rest of the package?

  3. Add an __init__.py file to the tests folder.

  4. Fix sagittal_brain.py (as you may remember from last week, 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 setup.py 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-MPHY0021-21-22/RSE-Classwork#37 in the pull request description), remember to mention your team members too! (with @github_username)

Metadata

Metadata

Assignees

No one assigned

    Labels

    week7Creating packages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions