Skip to content
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

Failure to recognize assignment as ignored #272

Closed
brodieG opened this issue Nov 24, 2020 · 2 comments
Closed

Failure to recognize assignment as ignored #272

brodieG opened this issue Nov 24, 2020 · 2 comments

Comments

@brodieG
Copy link
Owner

brodieG commented Nov 24, 2020

The assignment to error in addition to the display of it get both treated as tests, instead of only the latter of the two.

library(svgchop)

unitizer_sect("pixel match", 
  compare=function(ref, new) {
    if(length(ref) != length(new)) {
      sprintf("length mismatch (ref: %d new: %d)", length(ref), length(new))
    } else if (!identical(names(ref), names(new))) {
      "name mismatch"
    } else if (anyNA(new)) {
      "NA values in new"
    } else {
      thresh <- new - ref < -.01
      if(any(thresh))
        paste0(
          c("elements ", deparse(which(thresh)) ," exceed error threshold."),
          collapse=""
        )
      else TRUE
    }
  },
  {
    error <- local({
      page <- compare_rsvg(display=0, steps=50, quietly=TRUE)
      diffs <-
        list.files(dirname(page), full.names=TRUE, pattern="^diff.*\\.png$")
      setNames(
        vapply(diffs, function(x) mean(png::readPNG(x)), 0),
        sub(".*[0-9]{2}-(.*)\\.png$", "\\1", basename(diffs))
      )
    })
    error
  }
)
@brodieG brodieG added the bug label Nov 24, 2020
@brodieG brodieG added this to the 1.4.13 milestone Nov 24, 2020
@brodieG brodieG modified the milestones: 1.4.14, 1.4.16 Aug 1, 2021
@brodieG
Copy link
Owner Author

brodieG commented Jan 3, 2022

This is because the code in question emits uncaught, undisplayed conditions:

$conditions
$conditions[[1]]
<svgchop_unsupported: unit (cm) in <svg width='...'>.>

$conditions[[2]]
<svgchop_unsupported: unit (cm) in <svg height='...'>.>

$conditions[[3]]
<svgchop_unsupported: 'preserveAspectRatio' value 'xMidYMid' unsupported>

So the fix here is to display the conditions, although current behavior at the R prompt is to simply ignore these:

> res <- signalCondition(simpleCondition('hello'))
> 

I.e. without a handler, these might as well not exist. It really feels like unitizer should say something. The tension is that many conditions do usually manifest, e.g. by outputting to standard err or some other way. Perhaps what we need to do is only show the "additionally, 3 conditions were emitted, check .NEW$conditions" if there is no stderr output.

We can get to the conditions via .NEW, but the display is not ideal there either:

~~~ New Test ~~~
page <- compare_rsvg(display = 0, steps = 50, quietly = TRUE)
* value: chr[1]
* conditions:  

Access components with `$`, e.g. `.NEW$value`; see `help("$", "unitizer")`
unitizer> .NEW$conditions
Condition list with 3 conditions:
1. SimpleCondition: unit (cm) in <svg width='...'>.
2. SimpleCondition: unit (cm) in <svg height='...'>.
3. SimpleCondition: 'preserveAspectRatio' value 'xMidYMid' unsupported

Note class display for conditionList is bad, it should be showing "svgchop_unsupported", and the .NEW display is not telling us anything about the condition list.

@brodieG
Copy link
Owner Author

brodieG commented Mar 17, 2022

Loosely related to #229

brodieG added a commit that referenced this issue Mar 20, 2022
This still allows custom conditions to report leftmost
class as the condition, relates to #272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant