in reply to Testing image output
Should I manually verify the image it is supposed to create, then take a hash of that image and compare the hash from the same process during testing?
Sounds good to me.
If I do it this way, I will need to use a hashing module and I'm reluctant to create a dependency that is only used in the tests.
Digest::MD5 is a core module and has been since 5.7.3. You should have no qualms about relying on that one being present. Still declare it as a test dependency just in case for the 5.6.0 hold-outs.
🦛
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Testing image output
by Bod (Parson) on Sep 07, 2023 at 23:17 UTC | |
Thanks hippo I've used md5_hex from Digest::MD5 and checked it is installed as I've required Perl 5.010 Could I please have some feedback on this test file as testing is not my strongest skill...
| [reply] [d/l] [select] |
by eyepopslikeamosquito (Archbishop) on Sep 08, 2023 at 14:37 UTC | |
Could I please have some feedback on this test file as testing is not my strongest skill I pulled a face the instant I saw all those ok functions! From Basic Testing Tutorial by hippo: While the ok function is useful, the output is a simple pass/fail - it doesn't say how it failed ... Let's use Test::More and its handy cmp_ok function To convince yourself this is a worthwhile change, try running some failing test cases with your original ok and compare with cmp_ok. | [reply] [d/l] [select] |
by Bod (Parson) on Sep 08, 2023 at 23:22 UTC | |
Thanks for the bedtime reading...that might improve my abilities with Test::More 👍 To convince yourself this is a worthwhile change, try running some failing test cases with your original ok and compare with cmp_ok. I would take up your suggestion eyepopslikeamosquito but the tests don't fail for me...I would need to upload another dev release to CPAN and wait for some CPAN Testers to generate some results for me. There seem to be precious few testers these days as tests are getting longer and longer before they arrive. I don't want to unnecessarily burden those that are doing this sterling work! | [reply] [d/l] [select] |
by Bod (Parson) on Sep 13, 2023 at 21:55 UTC | |
To convince yourself this is a worthwhile change, try running some failing test cases with your original ok and compare with cmp_ok I took this advice... But, I don't see how it is any more helpful:
| [reply] [d/l] [select] |
by hippo (Archbishop) on Sep 13, 2023 at 23:05 UTC | |
by Anonymous Monk on Sep 08, 2023 at 10:48 UTC | |
It won't work as written. Neither coders nor decoders are stable. Does your module (can't find it on CPAN) inherit from GD (judging by width/height/jpeg methods)? It doesn't matter in the end, I only hope you force it to treat jpegs as truecolor on open, because it doesn't despite whatever its doco says. If GD converts jpeg to palette, it will be even more mess to add to description below -- looks like GD tunes this algo (true to palette quantization) more frequently, then no need to go as far back as 5.010 to demonstrate. Frog is frog
Blame ancient GD version? But
I'd say lossy codecs are murky waters and avoid them in tests:
Eh? What's the matter now? My first thought was zlib tunes its compression algo (despite same "level" 0..10), but it's not the reason for difference above -- though I strongly suspect it can influence the result for some input other than puny frog. But, above, it's just pHYs chunk that libpng decides to include from some version on. Then, what it all amounts to -- try stable (read: "obsolete") lossless coder with uncompressed output (GD can't dump raw pixels, unfortunately), short of enumerating pixels one by one and adding RGB to string. Hopefully it's OK now:
| [reply] [d/l] [select] |
by Bod (Parson) on Sep 08, 2023 at 23:17 UTC | |
Neither coders nor decoders are stable Do you mean the hashing coder/decoder or the image format? Does your module (can't find it on CPAN) inherit from GD (judging by width/height/jpeg methods)? Yes, it does use GD. It doesn't inherit from it. You can't find it on CPAN because it is still in development release. Although the module works under all visual testing, I wanted to get it working with a complete test suite before releasing it publicly. Yes, the module does use GD::Image-> trueColor( 1 ); and the tests specify $new->jpeg(50) rather than leaving GD to choose the best compression (whatever that means) as the docs say it does. I stayed away from PNG as I know that the exact behaviour of that depends on how GD was built, something that will vary on target machines. I hadn't thought of using a GD object to perform the comparison...obvious really...thanks... | [reply] [d/l] [select] |
by Anonymous Monk on Sep 09, 2023 at 11:23 UTC | |
|
Re^2: Testing image output
by Bod (Parson) on Sep 08, 2023 at 09:49 UTC | |
Sounds good to me It might sound like a good approach...but...it's failing under testing 😕 But, I'm not sure what could be producing this failure other than different builds of GD producing slightly different outputs or the hashing being subtly different on Linux where it is failing to Windows where I am developing. I specified the image quality with $new->jpeg(50) to try and keep GD consistent across builds. | [reply] [d/l] |
by hippo (Archbishop) on Sep 11, 2023 at 09:45 UTC | |
So, it's JPEG. :-) I agree with our Anonymous friend who wrote: no JPGs in t folder, because same image file can't be expected to decode to same data. Maybe use a lossless format instead for this level of testing and then separately just confirm that using JPEGs doesn't error out? Or else see how other JPEG modules handle it in their test suites. 🦛 | [reply] [d/l] |
by Anonymous Monk on Sep 14, 2023 at 18:10 UTC | |
omg, ain't GD so very difficult. I'm looking at Image-Square 0.01_4 testers matrix, what was supposed to be walk in the park is like blood covered battlefield. Half failures are from gd native output format unsupported, who could expect. I'm sorry. It isn't really a problem, because ".gd" is just 11 bytes header plus raw data:
Note, one checksum is exactly what "t/02-image.t line 41" was expecting, but the latter is what many (but not all) failures have "got". It appears that copyResampled (and interpolation in general, see further) is unstable between versions and plagued with bugs. Then, even generating synthetic gradient or whatever, and checking for just couple of pixels (e.g. lower left and upper right points) is NOT reliable way to test anything with GD, let alone calculating checksum over whole re-sampled image. No CoventryCathedral for tests below, simply a red 8 by 8 square to reduce to smaller squares:
Oh, I thought, but I'm copying red pixels to another (smaller) canvas, filled with default black. Maybe, instead, plain simple resize would preserve pure red colour? Note, plain "resize" was not implemented in old versions anyway.
Wait, but there are a few dozen interpolation methods:
I have no idea why 3,4,5 i.e. GD_BILINEAR_FIXED, GD_BICUBIC, GD_BICUBIC_FIXED, are not ok i.e. don't preserve dumb uniform fill of dumb square canvas. I'd laugh out load if asked will this list stay stable for near future. I have much sympathy for GD, but above was a little bit too much.
| [reply] [d/l] [select] |
by Bod (Parson) on Sep 14, 2023 at 22:53 UTC | |
omg, ain't GD so very difficult. I'm looking at Image-Square 0.01_4 testers matrix, what was supposed to be walk in the park is like blood covered battlefield. I know my knowledge of images is lacking but I was beginning to feel I had done something terribly wrong... No CoventryCathedral for tests below, simply a red 8 by 8 square to reduce to smaller squares Isn't the whole point of the tests to check that the module does what it is supposed to in real situations? Users of the module (me if I am the only one) will be using ti to process large, if not huge, images. If it passes the tests on little tiny images but fails on large ones, doesn't that sort of render the tests meaningless? My original tests were based on those in Image::Resize in the < href="https://metacpan.org/release/SHERZODR/Image-Resize-0.5/source/t/1.t"1.t</code> file which just checks the dimensions of the generated file. But that module doesn't crop images which is why I wanted to include tests of the actual output. It appears that copyResampled (and interpolation in general, see further) is unstable between versions and plagued with bugs I did originally use copy but changed to copyResampled when I decided it would be sensible to add the facility to change the size at the same time... | [reply] [d/l] [select] |
by pryrt (Abbot) on Sep 15, 2023 at 14:13 UTC | |
by Bod (Parson) on Sep 15, 2023 at 23:05 UTC | |
| |