|
1 | | -from invokeai.app.invocations.baseinvocation import BaseInvocation, BaseInvocationOutput, invocation, invocation_output |
| 1 | +from invokeai.app.invocations.baseinvocation import ( |
| 2 | + BaseInvocation, |
| 3 | + BaseInvocationOutput, |
| 4 | + InvalidVersionError, |
| 5 | + invocation, |
| 6 | + invocation_output, |
| 7 | +) |
2 | 8 | from .test_nodes import ( |
3 | 9 | ImageToImageTestInvocation, |
4 | 10 | TextToImageTestInvocation, |
@@ -616,18 +622,38 @@ def test_invocation_decorator(): |
616 | 622 | title = "Test Invocation" |
617 | 623 | tags = ["first", "second", "third"] |
618 | 624 | category = "category" |
| 625 | + version = "1.2.3" |
619 | 626 |
|
620 | | - @invocation(invocation_type, title=title, tags=tags, category=category) |
621 | | - class Test(BaseInvocation): |
| 627 | + @invocation(invocation_type, title=title, tags=tags, category=category, version=version) |
| 628 | + class TestInvocation(BaseInvocation): |
622 | 629 | def invoke(self): |
623 | 630 | pass |
624 | 631 |
|
625 | | - schema = Test.schema() |
| 632 | + schema = TestInvocation.schema() |
626 | 633 |
|
627 | 634 | assert schema.get("title") == title |
628 | 635 | assert schema.get("tags") == tags |
629 | 636 | assert schema.get("category") == category |
630 | | - assert Test(id="1").type == invocation_type # type: ignore (type is dynamically added) |
| 637 | + assert schema.get("version") == version |
| 638 | + assert TestInvocation(id="1").type == invocation_type # type: ignore (type is dynamically added) |
| 639 | + |
| 640 | + |
| 641 | +def test_invocation_version_must_be_semver(): |
| 642 | + invocation_type = "test_invocation" |
| 643 | + valid_version = "1.0.0" |
| 644 | + invalid_version = "not_semver" |
| 645 | + |
| 646 | + @invocation(invocation_type, version=valid_version) |
| 647 | + class ValidVersionInvocation(BaseInvocation): |
| 648 | + def invoke(self): |
| 649 | + pass |
| 650 | + |
| 651 | + with pytest.raises(InvalidVersionError): |
| 652 | + |
| 653 | + @invocation(invocation_type, version=invalid_version) |
| 654 | + class InvalidVersionInvocation(BaseInvocation): |
| 655 | + def invoke(self): |
| 656 | + pass |
631 | 657 |
|
632 | 658 |
|
633 | 659 | def test_invocation_output_decorator(): |
|
0 commit comments