| 
12 | 12 | #' * `expect_s4_class(x, class)` checks that `x` is an S4 object that  | 
13 | 13 | #'   [is()] `class`.  | 
14 | 14 | #' * `expect_s4_class(x, NA)` checks that `x` isn't an S4 object.  | 
 | 15 | +#' * `expect_s7_class(x, Class)` checks that `x` is an S7 object that  | 
 | 16 | +#'   [S7::S7_inherits()] from `Class`  | 
15 | 17 | #'  | 
16 | 18 | #' See [expect_vector()] for testing properties of objects created by vctrs.  | 
17 | 19 | #'  | 
@@ -92,6 +94,33 @@ expect_s3_class <- function(object, class, exact = FALSE) {  | 
92 | 94 |   invisible(act$val)  | 
93 | 95 | }  | 
94 | 96 | 
 
  | 
 | 97 | +#' @export  | 
 | 98 | +#' @rdname inheritance-expectations  | 
 | 99 | +expect_s7_class <- function(object, class) {  | 
 | 100 | +  check_installed("S7")  | 
 | 101 | +  if (!inherits(class, "S7_class")) {  | 
 | 102 | +    stop_input_type(class, "an S7 class object")  | 
 | 103 | +  }  | 
 | 104 | + | 
 | 105 | +  act <- quasi_label(enquo(object), arg = "object")  | 
 | 106 | + | 
 | 107 | +  if (!S7::S7_inherits(object)) {  | 
 | 108 | +    fail(sprintf("%s is not an S7 object", act$lab))  | 
 | 109 | +  } else {  | 
 | 110 | +    expect(  | 
 | 111 | +      S7::S7_inherits(object, class),  | 
 | 112 | +      sprintf(  | 
 | 113 | +        "%s inherits from %s not <%s>.",  | 
 | 114 | +        act$lab,  | 
 | 115 | +        paste0("<", setdiff(base::class(object), "S7_object"), ">", collapse = "/"),  | 
 | 116 | +        attr(class, "name", TRUE)  | 
 | 117 | +      )  | 
 | 118 | +    )  | 
 | 119 | +  }  | 
 | 120 | + | 
 | 121 | +  invisible(act$val)  | 
 | 122 | +}  | 
 | 123 | + | 
95 | 124 | #' @export  | 
96 | 125 | #' @rdname inheritance-expectations  | 
97 | 126 | expect_s4_class <- function(object, class) {  | 
 | 
0 commit comments