Skip to content

Move tests to dedicated directory #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def f(self, y) -> str: # noqa: F811
class NativeClassTypesTests(unittest.TestCase):
def test_class_name(self):
assert ClassWithInit.__name__ == 'ClassWithInit'
assert ClassWithInit.__module__ == 'typed_python.class_types_test'
assert ClassWithInit.__module__ == 'class_types_test'
assert ClassWithInit.__qualname__ == 'ClassWithInit'

def test_member_default_value(self):
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
OneFoldOnlyError,
PytzTimezone,
)
from typed_python.lib.datetime.date_parser_test import get_datetimes_in_range
from date_parser_test import get_datetimes_in_range
from typed_python.lib.timestamp import Timestamp


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def List(T):

def test_name_and_qualname(self):
assert TfLevelMethod.__name__ == 'TfLevelMethod'
assert TfLevelMethod.__module__ == 'typed_python.type_function_test'
assert TfLevelMethod.__module__ == 'type_function_test'
assert TfLevelMethod.__qualname__ == 'TfLevelMethod'

def test_mutually_recursive(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def looksAtFilename():


def looksAtFilename2():
return typed_python.type_identity_test.__file__
return __file__


def checkHash(filesToWrite, expression):
Expand Down Expand Up @@ -273,7 +273,8 @@ def test_mutually_recursive_group_basic():
X = Forward("X")
X = X.define(TupleOf(OneOf(int, X)))

assert recursiveTypeGroup(X) == [X, OneOf(int, X)]
assert (recursiveTypeGroup(X) == [X, OneOf(int, X)] or
recursiveTypeGroup(X) == [OneOf(int, X), X]) # order-independent


def test_mutually_recursive_group_through_functions_in_closure():
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ def test_serialize_mutually_recursive_unnamed_forwards_tuples(self):
def test_serialize_named_alternative(self):
self.assertEqual(
ModuleLevelAlternative.__module__,
"typed_python.types_serialization_test"
"types_serialization_test"
)

sc = SerializationContext()
Expand All @@ -1866,14 +1866,14 @@ def test_serialize_unnamed_recursive_alternative(self):
)

def test_serialize_module_level_class(self):
assert ModuleLevelClass.__module__ == 'typed_python.types_serialization_test'
assert ModuleLevelClass.__module__ == 'types_serialization_test'

sc = SerializationContext().withoutCompression()

self.assertIs(sc.deserialize(sc.serialize(ModuleLevelClass)), ModuleLevelClass)

self.assertIn(
b'typed_python.types_serialization_test.ModuleLevelClass',
b'types_serialization_test.ModuleLevelClass',
sc.serialize(ModuleLevelClass),
)

Expand All @@ -1899,7 +1899,7 @@ def test_serialize_named_subclass_of_named_tuple(self):

self.assertEqual(
ModuleLevelNamedTupleSubclass.__module__,
"typed_python.types_serialization_test"
"types_serialization_test"
)

self.assertEqual(
Expand Down Expand Up @@ -2031,7 +2031,7 @@ def f():
def getCellType():
return type(f.__closure__[0])

assert callFunctionInFreshProcess(getCellType, ()) is getCellType()
assert callFunctionInFreshProcess(getCellType, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)}) is getCellType()

def test_self_visible_base_class_forward_resolved(self):
Base = Forward("Base")
Expand Down Expand Up @@ -2060,7 +2060,7 @@ def __add__(self, other: Base) -> Base:

return Base, Child

Base, Child = callFunctionInFreshProcess(getOptimizer, ())
Base, Child = callFunctionInFreshProcess(getOptimizer, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

assert isinstance(Base() + Base() + Base(), Base)
assert isinstance(Base() + Base() + Base(), Child)
Expand All @@ -2082,7 +2082,7 @@ def g(self):

return C_

c = callFunctionInFreshProcess(C(int), ())
c = callFunctionInFreshProcess(C(int), (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

assert c.g() == 10
assert c.s() is type(c)
Expand All @@ -2106,7 +2106,7 @@ def g(self):

return C_

c = callFunctionInFreshProcess(C(int), ())
c = callFunctionInFreshProcess(C(int), (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})
assert c.g() == 10
assert c.s() is type(c)

Expand Down Expand Up @@ -2175,7 +2175,10 @@ def makeLenProxyWeirdGlobals():
assert lenProxy("asdf") == 4
assert lenProxyWithNonstandardGlobals("asdf") == 4

lenProxyDeserialized = callFunctionInFreshProcess(makeLenProxyWeirdGlobals, ())
lenProxyDeserialized = callFunctionInFreshProcess(makeLenProxyWeirdGlobals,
(),
extraEnvs={'PYTHONPATH': os.path.dirname(__file__)}
)

assert lenProxyDeserialized("asdf") == 4

Expand Down Expand Up @@ -2225,7 +2228,7 @@ def seeItself(self, a, b, c, d):

return SeesItself

SeesItself = callFunctionInFreshProcess(makeSeesItself, ())
SeesItself = callFunctionInFreshProcess(makeSeesItself, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

assert SeesItself.seeItself(1, 2, 3, 4, 5) is SeesItself

Expand Down Expand Up @@ -2275,7 +2278,7 @@ class Cls:
def f(self):
return Cls

assert callFunctionInFreshProcess(Cls().f, ()) is Cls
assert callFunctionInFreshProcess(Cls().f, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)}) is Cls

def test_serialization_preserves_forward_structure_in_classes(self):
def getCls():
Expand All @@ -2289,7 +2292,7 @@ def f(self) -> Cls:

return Cls

Cls = callFunctionInFreshProcess(getCls, (), showStdout=True)
Cls = callFunctionInFreshProcess(getCls, (), showStdout=True, extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})
assert Cls.f.__annotations__['return'].__typed_python_category__ == 'Forward'

Cls2 = getCls()
Expand All @@ -2304,7 +2307,7 @@ class Cls:
def f(self) -> Cls:
return "HI"

assert callFunctionInFreshProcess(Cls, ()).f() == "HI"
assert callFunctionInFreshProcess(Cls, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)}).f() == "HI"

def test_can_deserialize_untyped_forward_class_methods_2(self):
def getCls():
Expand All @@ -2318,7 +2321,7 @@ def f(self) -> Cls:

return Cls

callFunctionInFreshProcess(getCls, ())
callFunctionInFreshProcess(getCls, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

def test_can_deserialize_forward_class_methods_tp_class(self):
Cls = Forward("Cls")
Expand All @@ -2330,7 +2333,7 @@ class Cls(Class):
def f(self) -> Cls:
return Cls(m='HI')

assert callFunctionInFreshProcess(Cls, ()).f().m == "HI"
assert callFunctionInFreshProcess(Cls, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)}).f().m == "HI"

def test_can_deserialize_forward_class_methods_tp_class_no_self_reference(self):
Cls = Forward("Cls")
Expand All @@ -2342,7 +2345,7 @@ class Cls(Class):
def f(self) -> str:
return "HI"

assert callFunctionInFreshProcess(Cls, ()).f() == "HI"
assert callFunctionInFreshProcess(Cls, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)}).f() == "HI"

def test_deserialize_regular_class_retains_identity(self):
class Cls:
Expand All @@ -2351,7 +2354,7 @@ def f(self):
Cls
return "HI"

Cls2 = type(callFunctionInFreshProcess(Cls, ()))
Cls2 = type(callFunctionInFreshProcess(Cls, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)}))

assert identityHash(Cls).hex() == identityHash(Cls2).hex()

Expand All @@ -2367,7 +2370,7 @@ def f(x: float):

return (f, identityHash(f))

f, identityHashOfF = callFunctionInFreshProcess(makeFunction, ())
f, identityHashOfF = callFunctionInFreshProcess(makeFunction, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

assert identityHash(f) == identityHashOfF

Expand All @@ -2383,7 +2386,7 @@ def f(x=None):

return (f, identityHash(f))

f, identityHashOfF = callFunctionInFreshProcess(makeFunction, ())
f, identityHashOfF = callFunctionInFreshProcess(makeFunction, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

assert identityHash(f) == identityHashOfF

Expand All @@ -2399,7 +2402,7 @@ class Cls:
def f(self) -> Cls:
return Cls()

Cls2 = type(callFunctionInFreshProcess(Cls, ()))
Cls2 = type(callFunctionInFreshProcess(Cls, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)}))

l = recursiveTypeGroupDeepRepr(Cls).split("\n")
r = recursiveTypeGroupDeepRepr(Cls2).split("\n")
Expand Down Expand Up @@ -2429,7 +2432,7 @@ class Cls(Class):
def f(self) -> Cls:
return Cls()

Cls2 = type(callFunctionInFreshProcess(Cls, ()))
Cls2 = type(callFunctionInFreshProcess(Cls, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)}))

assert identityHash(Cls) == identityHash(Cls2)

Expand Down Expand Up @@ -2468,7 +2471,7 @@ def callF(x):
else:
return "FAILED"

assert callFunctionInFreshProcess(deserializeAndCall, (aChildBytes,)) == "OK"
assert callFunctionInFreshProcess(deserializeAndCall, (aChildBytes,), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)}) == "OK"

def test_call_method_dispatch_on_two_versions_of_self_referential_class_produced_differently(self):
def deserializeAndCall():
Expand All @@ -2492,8 +2495,8 @@ def f(self, x) -> int:

return Child(), callF

child1, callF1 = callFunctionInFreshProcess(deserializeAndCall, ())
child2, callF2 = callFunctionInFreshProcess(deserializeAndCall, ())
child1, callF1 = callFunctionInFreshProcess(deserializeAndCall, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})
child2, callF2 = callFunctionInFreshProcess(deserializeAndCall, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

assert identityHash(child1) == identityHash(child2)
assert identityHash(callF1) == identityHash(callF2)
Expand Down Expand Up @@ -2526,8 +2529,8 @@ def callF(x: Child):

return Base, callF

Base1, callF1 = callFunctionInFreshProcess(deserializeAndCall, ())
Base2, callF2 = callFunctionInFreshProcess(deserializeAndCall, ())
Base1, callF1 = callFunctionInFreshProcess(deserializeAndCall, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})
Base2, callF2 = callFunctionInFreshProcess(deserializeAndCall, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

assert identityHash(Base1) == identityHash(Base2)
assert identityHash(callF1) == identityHash(callF2)
Expand Down Expand Up @@ -2578,7 +2581,7 @@ def f(self, x) -> int:

return SerializationContext().serialize(Child())

childBytes = callFunctionInFreshProcess(deserializeAndCall, ())
childBytes = callFunctionInFreshProcess(deserializeAndCall, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

child1 = SerializationContext().deserialize(childBytes)
child2 = SerializationContext().deserialize(childBytes)
Expand Down Expand Up @@ -2606,7 +2609,7 @@ def aFun():

return s.serialize(aFun)

childBytes = callFunctionInFreshProcess(returnSerializedForm, ())
childBytes = callFunctionInFreshProcess(returnSerializedForm, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

childFun = (
SerializationContext()
Expand Down Expand Up @@ -2657,7 +2660,9 @@ def f(self):

return (BaseClass, ChildClass, ChildClass())

BaseClass, ChildClass, childInstance = callFunctionInFreshProcess(makeClasses, ())
BaseClass, ChildClass, childInstance = callFunctionInFreshProcess(makeClasses,
(),
extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

assert type(BaseClass) is ABCMeta

Expand Down Expand Up @@ -2695,7 +2700,7 @@ class ChildClass(BaseClass):

return (BaseClass, ChildClass, recursiveTypeGroupDeepRepr(BaseClass))

BaseClass, ChildClass, deepRepr = callFunctionInFreshProcess(makeClasses, ())
BaseClass, ChildClass, deepRepr = callFunctionInFreshProcess(makeClasses, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

assert type(BaseClass.getChild()) is ChildClass

Expand All @@ -2714,7 +2719,7 @@ def makeF():

return f

f = callFunctionInFreshProcess(makeF, ())
f = callFunctionInFreshProcess(makeF, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

assert f(10) == 10

Expand All @@ -2737,7 +2742,7 @@ class Child(Base):
return s.serialize(Child)

Child2 = SerializationContext().deserialize(
callFunctionInFreshProcess(serializeIt, ())
callFunctionInFreshProcess(serializeIt, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})
)

assert Child2().func() == 10
Expand Down Expand Up @@ -2776,7 +2781,7 @@ def makeF():
s = SerializationContext()
return s.serialize(globals['anF'])

serializedF = callFunctionInFreshProcess(makeF, ())
serializedF = callFunctionInFreshProcess(makeF, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

f = SerializationContext().deserialize(serializedF)

Expand Down Expand Up @@ -2813,7 +2818,7 @@ def makeC():
s = SerializationContext()
return s.serialize(globals['C'])

serializedC = callFunctionInFreshProcess(makeC, ())
serializedC = callFunctionInFreshProcess(makeC, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

C = SerializationContext().deserialize(serializedC)

Expand Down Expand Up @@ -2847,7 +2852,7 @@ def makeC():
s = SerializationContext()
return s.serialize(globals['C'])

serializedC = callFunctionInFreshProcess(makeC, ())
serializedC = callFunctionInFreshProcess(makeC, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

C = SerializationContext().deserialize(serializedC)

Expand Down Expand Up @@ -2887,8 +2892,12 @@ def makeF(modulename):
s = SerializationContext()
return s.serialize(globals['f'])

f1 = SerializationContext().deserialize(callFunctionInFreshProcess(makeF, ('asdf',)))
f2 = SerializationContext().deserialize(callFunctionInFreshProcess(makeF, ('asdf2',)))
f1 = SerializationContext().deserialize(callFunctionInFreshProcess(makeF,
('asdf',),
extraEnvs={'PYTHONPATH': os.path.dirname(__file__)}))
f2 = SerializationContext().deserialize(callFunctionInFreshProcess(makeF,
('asdf2',),
extraEnvs={'PYTHONPATH': os.path.dirname(__file__)}))

def checkSame(f1, f2):
s = SerializationContext().withoutCompression()
Expand Down Expand Up @@ -3023,15 +3032,14 @@ def makeC():

globals = {'__file__': path}

exec(
compile(CONTENTS, path, "exec"),
globals
)
exec(compile(CONTENTS, path, "exec"),
globals
)

s = SerializationContext()
return s.serialize(globals['f'])

serializedF = callFunctionInFreshProcess(makeC, ())
serializedF = callFunctionInFreshProcess(makeC, (), extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

f = SerializationContext().deserialize(serializedF)

Expand All @@ -3056,7 +3064,7 @@ def f(self):

return x

x = callFunctionInFreshProcess(getX, (), showStdout=True)
x = callFunctionInFreshProcess(getX, (), showStdout=True, extraEnvs={'PYTHONPATH': os.path.dirname(__file__)})

print(x)
# TODO: make this True
Expand Down
Loading