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

Creating a 🐍📦 with tests #44

Open
dpshelio opened this issue Nov 23, 2022 · 0 comments
Open

Creating a 🐍📦 with tests #44

dpshelio opened this issue Nov 23, 2022 · 0 comments
Labels
week07 Creating packages

Comments

@dpshelio
Copy link
Contributor

dpshelio commented Nov 23, 2022

Help Charlene to test her package (#43) (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 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-COMP0233-22-23/RSE-Classwork#44 in the pull request description), remember to mention your team members too! (with @github_username)


Sample solution:
UCL-COMP0233-2022-2023/sagittal_average#4

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

No branches or pull requests

1 participant