Skip to content

Commit

Permalink
chore: add python runtime tests (#1748)
Browse files Browse the repository at this point in the history
  • Loading branch information
AkhilJ321 authored Mar 27, 2024
1 parent 974afd5 commit fe88516
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 5 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/runtime-python-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Runtime testing Python Models

on:
push:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'src/generators/python/**'
- 'test/runtime/runtime-python/**'
jobs:
test:
name: Runtime testing Python Models
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check package-lock version
uses: asyncapi/.github/.github/actions/get-node-version-from-package-lock@master
id: lockversion
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '${{ steps.lockversion.outputs.version }}'
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Build library
run: npm install && npm run build:prod
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Generate Python models
run: npm run generate:runtime:python
- name: Run runtime tests
run: npm run test:runtime:python
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
"test:blackbox:cplusplus": "cross-env CI=true jest ./test/blackbox/blackbox-cplusplus.spec.ts",
"test:blackbox:java": "cross-env CI=true jest ./test/blackbox/blackbox-java.spec.ts",
"test:runtime:java": "cross-env CI=true jest ./test/runtime/runtime-java.spec.ts",
"test:runtime:python": "cross-env CI=true jest ./test/runtime/runtime-python.spec.ts",
"generate:runtime:python": "cross-env CI=true ts-node ./test/runtime/runtime-python.ts",
"generate:runtime:java": "cross-env CI=true ts-node ./test/runtime/runtime-java.ts",
"test:runtime:go": "cross-env CI=true jest ./test/runtime/runtime-go.spec.ts",
"generate:runtime:go": "cross-env CI=true ts-node ./test/runtime/runtime-go.ts",
Expand Down
7 changes: 2 additions & 5 deletions test/runtime/generic-input.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,11 @@
"type": "string"
}
},
"required": [
"house_number",
"array_type"
],
"required": ["house_number", "array_type"],
"$defs": {
"housing-types": {
"$id": "HousingType",
"enum": ["detached", "terraced", "bungalow", "flat"]
}
}
}
}
16 changes: 16 additions & 0 deletions test/runtime/runtime-python.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { execCommand } from "../blackbox/utils/Utils";
import path from "path";


jest.setTimeout(50000);

test("Python runtime testing", async () => {
// The 'python ' command here

const compileCommand = `cd ${path.resolve(
__dirname,
"./runtime-python/test/"
)} && python3 main.py`;
await execCommand(compileCommand,true);

});
21 changes: 21 additions & 0 deletions test/runtime/runtime-python.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { PYTHON_JSON_SERIALIZER_PRESET,PythonFileGenerator } from "../../";
import path from "path";

import input from "./generic-input.json";

const generator = new PythonFileGenerator({
presets: [PYTHON_JSON_SERIALIZER_PRESET],
});

generator.generateToFiles(
input,
path.resolve(
// eslint-disable-next-line no-undef
__dirname,
"./runtime-python/src/main/"
),
{}
);



2 changes: 2 additions & 0 deletions test/runtime/runtime-python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
myenv
main
38 changes: 38 additions & 0 deletions test/runtime/runtime-python/test/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import unittest
import sys
sys.path.insert(1, '../src/main/')
from Address import Address
from NestedObject import NestedObject
import json

class TestAddress(unittest.TestCase):
@classmethod
def setUpClass(cls) :
cls.address = Address(input=type('obj', (object,),{
'streetName' : "Test address 2",
'houseNumber' : 2,
'marriage' : True,
'members' : 2,
'arrayType' : [2, "test"],
'nestedObject' : NestedObject('test'),
'enumTest' : 'TEST',
'houseType' : 'DETACHED',
'roofType' : 'TILE',


}))


def test_serializeToJson(self):
json_str =self.address.serializeToJson()
self.assertIsInstance(json_str, str)

def test_should_not_contain_additional_properties_when_serialized(self):
json_str = self.address.serializeToJson()
self.assertNotIn('additionalProperties', json_str)




if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions test/runtime/runtime-typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async function generateDefaultExport() {
// eslint-disable-next-line no-undef
__dirname,
'./runtime-typescript/src/defaultExport'

),
{ exportType: 'default' }
);
Expand Down

0 comments on commit fe88516

Please sign in to comment.