Skip to content

Commit 60cc7dd

Browse files
chore:migrate remainin tests in generated_syntax to java
1 parent 4fdd723 commit 60cc7dd

File tree

6 files changed

+333
-324
lines changed

6 files changed

+333
-324
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.regnosys.rosetta.generator.python.generated_syntax;
2+
3+
import jakarta.inject.Inject;
4+
import com.regnosys.rosetta.tests.RosettaInjectorProvider;
5+
import com.regnosys.rosetta.generator.python.PythonGeneratorTestUtils;
6+
import org.eclipse.xtext.testing.InjectWith;
7+
import org.eclipse.xtext.testing.extensions.InjectionExtension;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.extension.ExtendWith;
10+
import java.util.Map;
11+
12+
@ExtendWith(InjectionExtension.class)
13+
@InjectWith(RosettaInjectorProvider.class)
14+
public class PythonChoiceGeneratorTest {
15+
16+
@Inject
17+
private PythonGeneratorTestUtils testUtils;
18+
19+
@Test
20+
public void testGeneration() {
21+
Map<String, CharSequence> python = testUtils.generatePythonFromString(
22+
"""
23+
namespace test.generated_syntax.semantic : <"generate Python unit tests from Rosetta.">
24+
25+
type Choice:
26+
intType int (0..1)
27+
stringType string (0..1)
28+
condition Choice: one-of
29+
""");
30+
31+
// check proxies
32+
testUtils.assertGeneratedContainsExpectedString(
33+
python.get("src/test/generated_syntax/semantic/Choice.py").toString(),
34+
"""
35+
# pylint: disable=unused-import
36+
from test._bundle import test_generated_syntax_semantic_Choice as Choice
37+
38+
# EOF
39+
""");
40+
41+
String generatedBundle = python.get("src/test/_bundle.py").toString();
42+
String expectedChoice = """
43+
class test_generated_syntax_semantic_Choice(BaseDataClass):
44+
_FQRTN = 'test.generated_syntax.semantic.Choice'
45+
intType: Optional[int] = Field(None, description='')
46+
stringType: Optional[str] = Field(None, description='')
47+
\s\s\s\s
48+
@rune_condition
49+
def condition_0_Choice(self):
50+
item = self
51+
return rune_check_one_of(self, 'intType', 'stringType', necessity=True)
52+
""";
53+
testUtils.assertGeneratedContainsExpectedString(generatedBundle, expectedChoice);
54+
}
55+
}

src/test/java/com/regnosys/rosetta/generator/python/generated_syntax/PythonChoiceGeneratorTest.xtend

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
package com.regnosys.rosetta.generator.python.generated_syntax;
2+
3+
import jakarta.inject.Inject;
4+
import com.regnosys.rosetta.tests.RosettaInjectorProvider;
5+
import com.regnosys.rosetta.generator.python.PythonGeneratorTestUtils;
6+
import org.eclipse.xtext.testing.InjectWith;
7+
import org.eclipse.xtext.testing.extensions.InjectionExtension;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.extension.ExtendWith;
10+
import static org.junit.jupiter.api.Assertions.assertTrue;
11+
import java.util.Map;
12+
13+
@ExtendWith(InjectionExtension.class)
14+
@InjectWith(RosettaInjectorProvider.class)
15+
public class PythonMetaDataGeneratorTest {
16+
17+
@Inject
18+
private PythonGeneratorTestUtils testUtils;
19+
20+
private Map<String, CharSequence> python = null;
21+
22+
private Map<String, CharSequence> getPython() {
23+
if (python == null) {
24+
python = testUtils.generatePythonFromString(
25+
"""
26+
namespace test.generated_syntax.metadata : <"generate Python unit tests from Rosetta.">
27+
28+
type A:
29+
[metadata key]
30+
fieldA string (1..1)
31+
32+
type NodeRef:
33+
typeA A (0..1)
34+
aReference A (0..1)
35+
[metadata reference]
36+
37+
type AttributeRef:
38+
dateField date (0..1)
39+
[metadata id]
40+
dateReference date (0..1)
41+
[metadata reference]
42+
43+
type Root:
44+
[rootType]
45+
nodeRef NodeRef (0..1)
46+
attributeRef AttributeRef (0..1)
47+
48+
type SchemeTest:
49+
[metadata scheme]
50+
a string (1..1)
51+
""");
52+
}
53+
return python;
54+
}
55+
56+
@Test
57+
public void testAProxy() {
58+
Map<String, CharSequence> python = getPython();
59+
testUtils.assertGeneratedContainsExpectedString(
60+
python.get("src/test/generated_syntax/metadata/A.py").toString(),
61+
"""
62+
# pylint: disable=unused-import
63+
from test._bundle import test_generated_syntax_metadata_A as A
64+
65+
# EOF
66+
""");
67+
}
68+
69+
@Test
70+
public void testNodeRefProxy() {
71+
Map<String, CharSequence> python = getPython();
72+
testUtils.assertGeneratedContainsExpectedString(
73+
python.get("src/test/generated_syntax/metadata/NodeRef.py").toString(),
74+
"""
75+
# pylint: disable=unused-import
76+
from test._bundle import test_generated_syntax_metadata_NodeRef as NodeRef
77+
78+
# EOF
79+
""");
80+
}
81+
82+
@Test
83+
public void testAttributeRefProxy() {
84+
Map<String, CharSequence> python = getPython();
85+
testUtils.assertGeneratedContainsExpectedString(
86+
python.get("src/test/generated_syntax/metadata/AttributeRef.py").toString(),
87+
"""
88+
# pylint: disable=unused-import
89+
from test._bundle import test_generated_syntax_metadata_AttributeRef as AttributeRef
90+
91+
# EOF
92+
""");
93+
}
94+
95+
@Test
96+
public void testRootProxy() {
97+
Map<String, CharSequence> python = getPython();
98+
testUtils.assertGeneratedContainsExpectedString(
99+
python.get("src/test/generated_syntax/metadata/Root.py").toString(),
100+
"""
101+
# pylint: disable=unused-import
102+
from test._bundle import test_generated_syntax_metadata_Root as Root
103+
104+
# EOF
105+
""");
106+
}
107+
108+
@Test
109+
public void testBundleExists() {
110+
Map<String, CharSequence> python = getPython();
111+
assertTrue(python.containsKey("src/test/_bundle.py"), "The bundle should be in the generated Python");
112+
}
113+
114+
@Test
115+
public void testExpectedBundleA() {
116+
Map<String, CharSequence> python = getPython();
117+
String generatedBundle = python.get("src/test/_bundle.py").toString();
118+
String expectedA = """
119+
class test_generated_syntax_metadata_A(BaseDataClass):
120+
_ALLOWED_METADATA = {'@key', '@key:external'}
121+
_FQRTN = 'test.generated_syntax.metadata.A'
122+
fieldA: str = Field(..., description='')
123+
""";
124+
testUtils.assertGeneratedContainsExpectedString(generatedBundle, expectedA);
125+
}
126+
127+
@Test
128+
public void testExpectedBundleAttributeRef() {
129+
Map<String, CharSequence> python = getPython();
130+
String generatedBundle = python.get("src/test/_bundle.py").toString();
131+
String expectedAttributeRef = """
132+
class test_generated_syntax_metadata_AttributeRef(BaseDataClass):
133+
_FQRTN = 'test.generated_syntax.metadata.AttributeRef'
134+
dateField: Optional[Annotated[DateWithMeta, DateWithMeta.serializer(), DateWithMeta.validator(('@key', '@key:external'))]] = Field(None, description='')
135+
dateReference: Optional[Annotated[DateWithMeta, DateWithMeta.serializer(), DateWithMeta.validator(('@ref', '@ref:external'))]] = Field(None, description='')
136+
\s\s\s\s
137+
_KEY_REF_CONSTRAINTS = {
138+
'dateField': {'@key', '@key:external'},
139+
'dateReference': {'@ref', '@ref:external'}
140+
}
141+
""";
142+
testUtils.assertGeneratedContainsExpectedString(generatedBundle, expectedAttributeRef);
143+
}
144+
145+
@Test
146+
public void testExpectedBundleNodeRef() {
147+
Map<String, CharSequence> python = getPython();
148+
String generatedBundle = python.get("src/test/_bundle.py").toString();
149+
String expectedNodeRef = """
150+
class test_generated_syntax_metadata_NodeRef(BaseDataClass):
151+
_FQRTN = 'test.generated_syntax.metadata.NodeRef'
152+
typeA: Optional[Annotated[test_generated_syntax_metadata_A, test_generated_syntax_metadata_A.serializer(), test_generated_syntax_metadata_A.validator()]] = Field(None, description='')
153+
aReference: Optional[Annotated[test_generated_syntax_metadata_A, test_generated_syntax_metadata_A.serializer(), test_generated_syntax_metadata_A.validator(('@key', '@key:external', '@ref', '@ref:external'))]] = Field(None, description='')
154+
\s\s\s\s
155+
_KEY_REF_CONSTRAINTS = {
156+
'aReference': {'@key', '@key:external', '@ref', '@ref:external'}
157+
}
158+
""";
159+
testUtils.assertGeneratedContainsExpectedString(generatedBundle, expectedNodeRef);
160+
}
161+
162+
@Test
163+
public void testExpectedBundleRoot() {
164+
Map<String, CharSequence> python = getPython();
165+
String generatedBundle = python.get("src/test/_bundle.py").toString();
166+
String expectedRoot = """
167+
class test_generated_syntax_metadata_Root(BaseDataClass):
168+
_FQRTN = 'test.generated_syntax.metadata.Root'
169+
nodeRef: Optional[Annotated[test_generated_syntax_metadata_NodeRef, test_generated_syntax_metadata_NodeRef.serializer(), test_generated_syntax_metadata_NodeRef.validator()]] = Field(None, description='')
170+
attributeRef: Optional[Annotated[test_generated_syntax_metadata_AttributeRef, test_generated_syntax_metadata_AttributeRef.serializer(), test_generated_syntax_metadata_AttributeRef.validator()]] = Field(None, description='')
171+
""";
172+
testUtils.assertGeneratedContainsExpectedString(generatedBundle, expectedRoot);
173+
}
174+
175+
@Test
176+
public void testExpectedBundleScheme() {
177+
Map<String, CharSequence> python = getPython();
178+
String generatedBundle = python.get("src/test/_bundle.py").toString();
179+
String expectedScheme = """
180+
class test_generated_syntax_metadata_SchemeTest(BaseDataClass):
181+
_ALLOWED_METADATA = {'@scheme'}
182+
_FQRTN = 'test.generated_syntax.metadata.SchemeTest'
183+
a: str = Field(..., description='')
184+
""";
185+
testUtils.assertGeneratedContainsExpectedString(generatedBundle, expectedScheme);
186+
}
187+
}

0 commit comments

Comments
 (0)