adamchainz,
@adamchainz@fosstodon.org avatar

✍️ New post covering a “diffing” unit test in , which checks copy-paste-tweaked code is in sync with the upstream library.

I used this technique recently on a upgrade and I’m curious if anyone else has done similar.

https://adamj.eu/tech/2024/04/26/python-diffing-unit-test/

radiac,
@radiac@mastodon.cloud avatar

@adamchainz I've done similar with class/fn copies, but take a snapshot hash of the function I've copied and save it to a json file next to the test.

adamchainz,
@adamchainz@fosstodon.org avatar

@radiac a hash is easy but doesn’t really help debug what changed. I guess there’s git for that though.

webology,
@webology@mastodon.social avatar

@adamchainz Cc @josh since this might save some hair being pulled out for a shared theme and fields template project. 🤔

I did have a strange linting/auto-formatting cause a textarea to prepend 4 to 8 spaces in front of values that I had to turn off on a few projects that wasn’t immediately obvious.

josh,
@josh@joshthomas.dev avatar

@webology @adamchainz oh yeah way ahead of you, totally copying this when I get back in the office Monday for the form templates

carlton,
@carlton@fosstodon.org avatar

@adamchainz nice. That’s the sort of real-world dirty that I’m here for. 👏

mistersql,
@mistersql@mastodon.social avatar

@adamchainz This sounds very similar to snapshot testing (where the output of a long string is saved & the test fails when the string changes... the snapshot tool shows a diff & you decide if you wanted that diff).

This also sounds like how I'd implement a "pip install" for a gist or a stackoverflow question, both of which evolve & are not real packages, so they'd need ad hoc tooling support.

mistersql,
@mistersql@mastodon.social avatar

@adamchainz I put way to much time into treating an stackoverflow answer as a library, but never got around to fully implementing the update part because so few answers are fully usable as-is.

https://github.com/matthewdeanmartin/so_pip

adamchainz,
@adamchainz@fosstodon.org avatar

@mistersql Yes, it’s definitely a variant of snapshot testing.

Updates of SO posts are interesting. So many “updates” are actually another user replying years later with a better alternative...

diazona,
@diazona@techhub.social avatar

@adamchainz Neat, this is one of those things that seems like it should normally come with a disclaimer "for entertainment value only, do not use", but on the rare occasion that you need it....

I wonder if there's a better way to present the diff of diffs that could be built into a custom output hook? 🤔

adamchainz,
@adamchainz@fosstodon.org avatar

@diazona I tried to cover alternatives first, and let engineers decide. I can’t say I did this for “entertainment” 😆

Maybe there is a better diff-of-diff presentation. Git has its three-way diff format used for merge commits - maybe that could be used. Still hard to read though.

josh,
@josh@joshthomas.dev avatar

@adamchainz oh, this is so good. I try to avoid getting in this position, but sometimes it’s unavoidable. Quickly adopting this approach the few places I’ve done this. 🎉

adamchainz,
@adamchainz@fosstodon.org avatar

@josh Glad to share! Good luck.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • python
  • kavyap
  • thenastyranch
  • Durango
  • DreamBathrooms
  • ngwrru68w68
  • magazineikmin
  • cisconetworking
  • Youngstown
  • mdbf
  • slotface
  • osvaldo12
  • GTA5RPClips
  • rosin
  • InstantRegret
  • provamag3
  • everett
  • cubers
  • vwfavf
  • normalnudes
  • tacticalgear
  • tester
  • ethstaker
  • khanakhh
  • modclub
  • Leos
  • anitta
  • megavids
  • JUstTest
  • All magazines