(expr, visitor_str, mutator_str)
| 350 | |
| 351 | |
| 352 | def basic_check(expr, visitor_str, mutator_str): |
| 353 | def visit(f, expr): |
| 354 | if isinstance(expr, relax.Expr): |
| 355 | return f.visit_expr(expr) |
| 356 | elif isinstance(expr, relax.BindingBlock): |
| 357 | return f.visit_binding_block(expr) |
| 358 | |
| 359 | # check no overloading case |
| 360 | basic_visitor = BasicVisitor() |
| 361 | visit(basic_visitor, expr) |
| 362 | |
| 363 | # check the output log |
| 364 | log_visitor = ASTPrinter() |
| 365 | visit(log_visitor, expr) |
| 366 | assert str(log_visitor.log) == visitor_str |
| 367 | |
| 368 | # check no overloading case |
| 369 | basic_mutator = BasicMutator() |
| 370 | # skip normalize GlobalVar since it requires context IRModule to get the struct_info_ |
| 371 | if isinstance(expr, relax.Expr) and not isinstance(expr, relax.GlobalVar): |
| 372 | expr = bb.normalize(expr) |
| 373 | assert_structural_equal(visit(basic_mutator, expr), expr) |
| 374 | |
| 375 | # check the output log and return value |
| 376 | post_log_mutator = ASTPostPrinterMutator() |
| 377 | if isinstance(expr, relax.Expr) and not isinstance(expr, relax.GlobalVar): |
| 378 | expr = bb.normalize(expr) |
| 379 | assert_structural_equal(visit(post_log_mutator, expr), expr) |
| 380 | assert str(post_log_mutator.log) == mutator_str |
| 381 | |
| 382 | |
| 383 | def test_constant(): |
no test coverage detected
searching dependent graphs…