Coverage for pyfields/tests/issues/_test_py36.py: 97%

30 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-11-06 16:35 +0000

1# Authors: Sylvain Marie <sylvain.marie@se.com> 

2# 

3# Copyright (c) Schneider Electric Industries, 2019. All right reserved. 

4 

5from pyfields import field, init_fields, autofields, autoclass 

6 

7 

8def test_issue_51(): 

9 class A: 

10 f: str = field(check_type=True, default=None, nonable=True) 

11 

12 @init_fields 

13 def __init__(self): 

14 pass 

15 

16 return A 

17 

18 

19def test_issue_67(): 

20 @autofields 

21 class Frog: 

22 another: int = 1 

23 

24 @property 

25 def balh(self): 

26 print('asd') 

27 

28 return Frog 

29 

30 

31def test_issue_73(): 

32 class Foo: 

33 bar: 'Foo' = field(check_type=True, nonable=True) 

34 return Foo 

35 

36 

37class A: 

38 bar: 'B' = field(check_type=True, nonable=True) 

39 

40class B: 

41 bar: 'A' = field(check_type=True, nonable=True) 

42 

43 

44def test_issue_73_cross_ref(): 

45 # note: we have to define the classes outside the function for the cross-ref to work 

46 # indeed typing.get_type_hints() will only access the globals of the defining module 

47 return A, B 

48 

49 

50def test_issue_81(): 

51 

52 # note that the issue comes from autofields actually, but it was detected using autoclass 

53 

54 @autoclass 

55 class A: 

56 a: int = 1 

57 

58 @autoclass 

59 class B(A): 

60 b = 0 

61 

62 return A, B