I was writing a program to process some CSV data, exported from a vendor. And it has a date-time column in some creative, funky format.
To help with ingesting this into a Pandas dataframe, I wrote a converter function: it takes that string, and returns a Python datetime object. Simple, right?
But you know, this is a PERFECT place to write a unit test. And I decided to use Pytest, starting with this simple test:
from datetime import datetime from myprog import parse_vendor_datetime
def test_parse_vendor_datetime (): actual = parse_vendor_datetime ( ' 12/25/38 1:14am EST ' ) expected = datetime ( 2038 , 12 , 25 , 1 , 14 ) assert expected == actual
Enter fullscreen mode
Exit fullscreen mode
I run the test, and it fails, like it should. Then I write parse_vendor_datetime(), and the test passes. Great!
Now, what no one ever talks about is how TDD works with version control.…