Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arc-teaching/1a91d52ac4e26e6ff22b6a7e9e030ac3 to your computer and use it in GitHub Desktop.
Save arc-teaching/1a91d52ac4e26e6ff22b6a7e9e030ac3 to your computer and use it in GitHub Desktop.

Create a file called test_sagital_average.py which contains an assertion that fails if the current commit is bad. The contents of this file might look a bit like the following:

import subprocess
import numpy as np

# Create input file
data_input = np.zeros((20,20))
data_input[-1, :] = 1

# The expected result
expected = np.zeros(20)
expected[-1] = 1

np.savetxt("brain_sample.csv", data_input, fmt='%d', delimiter=',')

# Run the progam
subprocess.run(["python", "sagital_brain.py"])

result = np.loadtxt('brain_average.csv', delimiter=',')
np.testing.assert_array_equal(result, expected)

Then, use git bisect's automated run functionality to find the faulty commit:

 git bisect start
 git bisect bad HEAD
 git bisect good 034d01 # we know it worked after the first commit, so use this as good
 git bisect run python test_sagital_average.py

This avoids having to repeatedly type git bisect good/bad and running the python code manually at each step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment