-
Notifications
You must be signed in to change notification settings - Fork 57
More unit tests for util #192
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
More unit tests for util #192
Conversation
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
| } | ||
| else | ||
| { | ||
| check_and_add_file( path, batches[0] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was actually a bug cought by the unit test. Horray for unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what makes you think this was a bug? the code does exactly what was intended, see main.cpp#40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right. That is rather specific expectation. If it was private API and used internally, I'd see no problem with that. But expecting caller to know that expectation seems specific. Happy to revert and modify the test. You can imagine test is failing when std::vector<std::vector<std::string>> batches; is empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the split between main/util is not optimal here, perhaps the outer loop (main.cpp#44) should be also moved inside collect_image_files.
My point is, creating a new batch for each individual file was not the intended use.
The logic was: rawtoaces file1 file2 dir1 dir2 file3 should create 3 batches: [file1, file2, file3], [dir1/*], [dir2/*]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right. I didn't know it was intended behaviour. Now I know. I've refactored basd on your suggestion. Now there is no need for boolean return, so batches is the return now. I've added a test that checks that exact behaviour.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #192 +/- ##
==========================================
+ Coverage 71.40% 73.29% +1.89%
==========================================
Files 10 10
Lines 2196 2198 +2
Branches 236 237 +1
==========================================
+ Hits 1568 1611 +43
+ Misses 628 587 -41
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
| namespace util | ||
| { | ||
|
|
||
| bool collect_image_files( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is public API, so I guess I can drop it and use one from /include if you want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes please, no need to duplicate things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Signed-off-by: Aleksandr Motsjonov <[email protected]>
| * false if the file should be ignored | ||
| */ | ||
| bool check_and_add_file( | ||
| void check_and_add_file( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boolean is not used in any way
| } | ||
| else | ||
| { | ||
| check_and_add_file( path, batches[0] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what makes you think this was a bug? the code does exactly what was intended, see main.cpp#40
| namespace util | ||
| { | ||
|
|
||
| bool collect_image_files( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes please, no need to duplicate things.
tests/test_image_converter.cpp
Outdated
| catch ( const std::exception &e ) | ||
| { | ||
| std::cerr << "Exception caught in main: " << e.what() << std::endl; | ||
| return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not that this is important, but should this be return unit_test_failures + 1;, as returning 1 discards all other failures we've found so far
tests/test_image_converter.cpp
Outdated
| OIIO::ImageSpec spec; | ||
|
|
||
| // Add integer attribute (this should be ignored by fix_metadata) | ||
| spec["Make"] = 42; // Integer, not string or float |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we think that camera make can be float, but not int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know 🤷 That's the main problem not doing TDD and writing tests (contract) after impl. was written. (especially by a different brain)
if ( type.basetype == OIIO::TypeDesc::STRING )
spec[dst_name] = src_attribute->get_string();
else if ( type.basetype == OIIO::TypeDesc::FLOAT )
spec[dst_name] = src_attribute->get_float();
You tell me why we want attribute to be allows in as a float and a string, but not int. Happy to fix prod. code if there is a way to remove it.
This test just tests functionality that is already there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see what happened. The fix_metadata() originally had more attributes than just make and model. Could you delete that "else if float" branch for now, we'll add the allowed types to the mapping dictionary later when needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. makes sense. I am very big fan of removing code =)
tests/test_image_converter.cpp
Outdated
| } | ||
|
|
||
| /// Tests database_paths with Windows-style path separator | ||
| void test_database_paths_windows_separator() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we test the windows separator, but no the unix one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't need it. it's kinda stupid. If someone changes window separator, test_database_paths_default would brake.
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
| } ), | ||
| batches.end() ); | ||
|
|
||
| return batches; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see how it is used later on in main
for ( auto const &batch: batches )
{
for ( auto const &input_filename: batch )
{
so, this ^ would deal with empty batches no problem, but from API perspective it doesn't make sense to have empty batch in return. So removing empty won't brake consumer, but make result cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does make sense though. It really depends on how the client needs the pipeline organised.
Example: rawtoaces dir1 dir2 dir3, if it returns 2 batches, there is no way to know which one was empty on the client side if it is removed in lib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. I've reverted it back. Empty batches are back.
Signed-off-by: Aleksandr Motsjonov <[email protected]>
Signed-off-by: Aleksandr Motsjonov <[email protected]>
No description provided.