Implemented unit test for NewType.

This commit is contained in:
Eric Traut 2019-08-08 00:58:39 -07:00
parent b7e37f12a9
commit 249dfa556d
2 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,18 @@
# This sample tests the type handler's handling of the
# built-in NewType function.
from typing import NewType
MyString = NewType('MyString', str)
def must_take_string(p1: str): pass
must_take_string(MyString('hello'))
def must_take_my_string(p1: MyString): pass
must_take_my_string(MyString('hello'))
# This should generate an error because 'hello'
# isn't a valid MyString.
must_take_my_string('hello')

View File

@ -481,3 +481,10 @@ test('Super1', () => {
validateResults(analysisResults, 4);
});
test('NewType1', () => {
let analysisResults = TestUtils.typeAnalyzeSampleFiles(['newType1.py']);
validateResults(analysisResults, 1);
});