Finish tests for Python syntax extraction and comparison
This commit is contained in:
Родитель
f94a35c9e7
Коммит
04fef8dc05
|
@ -67,7 +67,7 @@ export function extractMethod(methodNode: Parser.SyntaxNode): MethodDetails {
|
|||
|
||||
return {
|
||||
name: (methodNode as any).nameNode.text,
|
||||
returnType: returnTypeNode ? returnTypeNode.text : "",
|
||||
returnType: returnTypeNode ? returnTypeNode.text : undefined,
|
||||
body: bodyNode.text,
|
||||
parameters: parameterNodes.map(extractParameter)
|
||||
};
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
from typing import Optional
|
||||
|
||||
import msrest.serialization
|
||||
|
||||
class Error(msrest.serialization.Model2):
|
||||
"""Error.
|
||||
|
||||
:param status:
|
||||
:type status: int
|
||||
:param message:
|
||||
:type message: str
|
||||
"""
|
||||
_EXCEPTION_TYPE = ErrorException
|
||||
_attribute_map = {
|
||||
'status': {'key': 'status', 'type': 'str'},
|
||||
'message': {'key': 'message', 'type': 'str'},
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
status: Optional[int] = None,
|
||||
message: Optional[str] = "gorp",
|
||||
**kwargs
|
||||
):
|
||||
super(Error, self).__init__(**kwargs)
|
||||
self.status = status
|
||||
self.message = message
|
||||
|
||||
|
||||
class RefColorConstant(msrest.serialization.Model2):
|
||||
"""RefColorConstant.
|
||||
|
||||
Variables are only populated by the server, and will be ignored when sending a request.
|
||||
|
||||
All required parameters must be populated in order to send to Azure.
|
||||
|
||||
:ivar color_constant: Required. Referenced Color Constant Description. Default value: "green-
|
||||
color".
|
||||
:vartype color_constant: str
|
||||
:param field1: Sample string.
|
||||
:type field1: str
|
||||
"""
|
||||
|
||||
color_constant = "purple-color"
|
||||
other_thing = "whatever"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
field1: Optional[str] = 22,
|
||||
**kwargs
|
||||
): InvalidButOK
|
||||
super(RefColorConstant, self).__init__(**kwargs)
|
||||
self.field1 = field1
|
|
@ -0,0 +1,54 @@
|
|||
from typing import Optional
|
||||
|
||||
import msrest.serialization
|
||||
|
||||
class Error(msrest.serialization.Model):
|
||||
"""Error.
|
||||
|
||||
:param status:
|
||||
:type status: int
|
||||
:param message:
|
||||
:type message: str
|
||||
"""
|
||||
|
||||
_attribute_map = {
|
||||
'status': {'key': 'status', 'type': 'int'},
|
||||
'message': {'key': 'message', 'type': 'str'},
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
status: Optional[int] = None,
|
||||
message: Optional[str] = None,
|
||||
**kwargs
|
||||
):
|
||||
super(Error, self).__init__(**kwargs)
|
||||
self.status = status
|
||||
self.message = message
|
||||
|
||||
|
||||
class RefColorConstant(msrest.serialization.Model):
|
||||
"""RefColorConstant.
|
||||
|
||||
Variables are only populated by the server, and will be ignored when sending a request.
|
||||
|
||||
All required parameters must be populated in order to send to Azure.
|
||||
|
||||
:ivar color_constant: Required. Referenced Color Constant Description. Default value: "green-
|
||||
color".
|
||||
:vartype color_constant: str
|
||||
:param field1: Sample string.
|
||||
:type field1: str
|
||||
"""
|
||||
|
||||
color_constant = "green-color"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
field1: Optional[str] = None,
|
||||
**kwargs
|
||||
):
|
||||
super(RefColorConstant, self).__init__(**kwargs)
|
||||
self.field1 = field1
|
|
@ -2,33 +2,347 @@ import * as assert from "assert";
|
|||
import * as path from "path";
|
||||
import {
|
||||
parseFile,
|
||||
compareFile,
|
||||
extractSourceDetails,
|
||||
SourceDetails
|
||||
// compareClass,
|
||||
// compareInterface,
|
||||
// compareParameter,
|
||||
// compareMethod
|
||||
} from "../../src/languages/python";
|
||||
import { MessageType } from "../../src/comparers";
|
||||
|
||||
describe.only("Python Parser", function() {
|
||||
it("extracts semantic elements from source", function() {
|
||||
const parseTree = parseFile(
|
||||
path.resolve(__dirname, "../artifacts/python/old/test.py")
|
||||
path.resolve(__dirname, "../artifacts/python/old/models.py")
|
||||
);
|
||||
const sourceDetails: SourceDetails = extractSourceDetails(parseTree);
|
||||
|
||||
assert.deepEqual(sourceDetails, {
|
||||
classes: [
|
||||
{
|
||||
name: "Operations",
|
||||
methods: [],
|
||||
assignments: []
|
||||
name: "Error",
|
||||
superclasses: [
|
||||
{
|
||||
name: "msrest.serialization.Model"
|
||||
}
|
||||
],
|
||||
methods: [
|
||||
{
|
||||
name: "__init__",
|
||||
body:
|
||||
"super(Error, self).__init__(**kwargs)\n self.status = status\n self.message = message",
|
||||
parameters: [
|
||||
{
|
||||
name: "self",
|
||||
type: undefined,
|
||||
defaultValue: undefined
|
||||
},
|
||||
{
|
||||
name: "*",
|
||||
type: undefined,
|
||||
defaultValue: undefined
|
||||
},
|
||||
{
|
||||
name: "status",
|
||||
type: "Optional[int]",
|
||||
defaultValue: "None"
|
||||
},
|
||||
{
|
||||
name: "message",
|
||||
type: "Optional[str]",
|
||||
defaultValue: "None"
|
||||
},
|
||||
{
|
||||
name: "**kwargs",
|
||||
type: undefined,
|
||||
defaultValue: undefined
|
||||
}
|
||||
],
|
||||
returnType: undefined
|
||||
}
|
||||
],
|
||||
assignments: [
|
||||
{
|
||||
name: "_attribute_map",
|
||||
value:
|
||||
"{\n 'status': {'key': 'status', 'type': 'int'},\n 'message': {'key': 'message', 'type': 'str'},\n }"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "RedisFirewallRule",
|
||||
methods: [],
|
||||
assignments: []
|
||||
name: "RefColorConstant",
|
||||
superclasses: [
|
||||
{
|
||||
name: "msrest.serialization.Model"
|
||||
}
|
||||
],
|
||||
assignments: [
|
||||
{
|
||||
name: "color_constant",
|
||||
value: '"green-color"'
|
||||
}
|
||||
],
|
||||
methods: [
|
||||
{
|
||||
name: "__init__",
|
||||
body:
|
||||
"super(RefColorConstant, self).__init__(**kwargs)\n self.field1 = field1",
|
||||
parameters: [
|
||||
{
|
||||
name: "self",
|
||||
type: undefined,
|
||||
defaultValue: undefined
|
||||
},
|
||||
{
|
||||
name: "*",
|
||||
type: undefined,
|
||||
defaultValue: undefined
|
||||
},
|
||||
{
|
||||
name: "field1",
|
||||
type: "Optional[str]",
|
||||
defaultValue: "None"
|
||||
},
|
||||
{
|
||||
name: "**kwargs",
|
||||
type: undefined,
|
||||
defaultValue: undefined
|
||||
}
|
||||
],
|
||||
returnType: undefined
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it("compares source files and finds changes", () => {
|
||||
const basePath = path.resolve(__dirname, "../artifacts/python");
|
||||
const compareResult = compareFile(
|
||||
{
|
||||
name: "models.py",
|
||||
basePath: basePath + "/old/"
|
||||
},
|
||||
{
|
||||
name: "models.py",
|
||||
basePath: basePath + "/new/"
|
||||
}
|
||||
);
|
||||
|
||||
assert.deepEqual(compareResult, {
|
||||
message: "models.py",
|
||||
type: MessageType.Changed,
|
||||
children: [
|
||||
{
|
||||
message: "Classes",
|
||||
type: MessageType.Outline,
|
||||
children: [
|
||||
{
|
||||
message: "Error",
|
||||
type: MessageType.Changed,
|
||||
children: [
|
||||
{
|
||||
message: "Superclasses",
|
||||
type: MessageType.Outline,
|
||||
children: [
|
||||
{
|
||||
message: "msrest.serialization.Model",
|
||||
type: MessageType.Removed
|
||||
},
|
||||
{
|
||||
message: "msrest.serialization.Model2",
|
||||
type: MessageType.Added
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
message: "Methods",
|
||||
type: MessageType.Outline,
|
||||
children: [
|
||||
{
|
||||
message: "__init__",
|
||||
type: MessageType.Changed,
|
||||
children: [
|
||||
{
|
||||
message: "Parameters",
|
||||
type: MessageType.Outline,
|
||||
children: [
|
||||
{
|
||||
message: "message",
|
||||
type: MessageType.Changed,
|
||||
children: [
|
||||
{
|
||||
message: "Default Value",
|
||||
type: MessageType.Outline,
|
||||
children: [
|
||||
{
|
||||
message: "None",
|
||||
type: MessageType.Removed
|
||||
},
|
||||
{
|
||||
message: '"gorp"',
|
||||
type: MessageType.Added
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
message: "Fields",
|
||||
type: MessageType.Outline,
|
||||
children: [
|
||||
{
|
||||
message: "_EXCEPTION_TYPE",
|
||||
type: MessageType.Added
|
||||
},
|
||||
{
|
||||
message: "_attribute_map",
|
||||
type: MessageType.Changed,
|
||||
children: [
|
||||
{
|
||||
message: "Value",
|
||||
type: MessageType.Outline,
|
||||
children: [
|
||||
{
|
||||
message: "{\n",
|
||||
type: MessageType.Plain
|
||||
},
|
||||
{
|
||||
message:
|
||||
" 'status': {'key': 'status', 'type': 'int'},\n",
|
||||
type: MessageType.Removed
|
||||
},
|
||||
{
|
||||
message:
|
||||
" 'status': {'key': 'status', 'type': 'str'},\n",
|
||||
type: MessageType.Added
|
||||
},
|
||||
{
|
||||
message:
|
||||
" 'message': {'key': 'message', 'type': 'str'},\n }",
|
||||
type: MessageType.Plain
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
message: "RefColorConstant",
|
||||
type: MessageType.Changed,
|
||||
children: [
|
||||
{
|
||||
message: "Superclasses",
|
||||
type: MessageType.Outline,
|
||||
children: [
|
||||
{
|
||||
message: "msrest.serialization.Model",
|
||||
type: MessageType.Removed
|
||||
},
|
||||
{
|
||||
message: "msrest.serialization.Model2",
|
||||
type: MessageType.Added
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
message: "Methods",
|
||||
type: 0,
|
||||
children: [
|
||||
{
|
||||
message: "__init__",
|
||||
type: 4,
|
||||
children: [
|
||||
{
|
||||
message: "Parameters",
|
||||
type: 0,
|
||||
children: [
|
||||
{
|
||||
message: "field1",
|
||||
type: 4,
|
||||
children: [
|
||||
{
|
||||
message: "Default Value",
|
||||
type: 0,
|
||||
children: [
|
||||
{
|
||||
message: "None",
|
||||
type: 3
|
||||
},
|
||||
{
|
||||
message: "22",
|
||||
type: 2
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
message: "Body",
|
||||
type: 0,
|
||||
children: [
|
||||
{
|
||||
message:
|
||||
"super(RefColorConstant, self).__init__(**kwargs)\n self.field1 = field1",
|
||||
type: 3
|
||||
},
|
||||
{
|
||||
message: "InvalidButOK",
|
||||
type: 2
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
message: "Fields",
|
||||
type: MessageType.Outline,
|
||||
children: [
|
||||
{
|
||||
message: "color_constant",
|
||||
type: MessageType.Changed,
|
||||
children: [
|
||||
{
|
||||
message: "Value",
|
||||
type: MessageType.Outline,
|
||||
children: [
|
||||
{
|
||||
message: '"green-color"',
|
||||
type: MessageType.Removed
|
||||
},
|
||||
{
|
||||
message: '"purple-color"',
|
||||
type: MessageType.Added
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
message: "other_thing",
|
||||
type: MessageType.Added
|
||||
},
|
||||
{
|
||||
message: "self.field1",
|
||||
type: MessageType.Added
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
|
|
|
@ -5,7 +5,6 @@ import {
|
|||
extractSourceDetails,
|
||||
SourceDetails,
|
||||
compareClass,
|
||||
compareInterface,
|
||||
compareParameter,
|
||||
compareMethod
|
||||
} from "../../src/languages/typescript";
|
||||
|
|
Загрузка…
Ссылка в новой задаче