Skip to content

Commit e0e213a

Browse files
committed
add diamond inheritance test #131
1 parent bb33af2 commit e0e213a

File tree

5 files changed

+203
-0
lines changed

5 files changed

+203
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Test that multi-level and multiple inheritance resolves correctly.
3+
"""
4+
5+
from django_typer.management import TyperCommand, command, group, initialize
6+
7+
8+
class Command(TyperCommand):
9+
"""
10+
Inheritance1
11+
"""
12+
13+
@initialize(invoke_without_command=True)
14+
def init(self):
15+
assert isinstance(self, Command)
16+
return "inheritance1::init()"
17+
18+
@command()
19+
def a(self):
20+
assert isinstance(self, Command)
21+
return "inheritance1::a()"
22+
23+
@group(invoke_without_command=True)
24+
def g(self):
25+
assert isinstance(self, Command)
26+
return "inheritance1::g()"
27+
28+
@g.command()
29+
def ga(self):
30+
assert isinstance(self, Command)
31+
return "inheritance1::g::ga()"
32+
33+
@g.command()
34+
def gb(self):
35+
assert isinstance(self, Command)
36+
return "inheritance1::g::gb()"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from django_typer.management import TyperCommand, command, group, initialize
2+
from .inheritance1 import Command as Inheritance1Command
3+
4+
5+
class Command(Inheritance1Command):
6+
"""
7+
Inheritance2_1
8+
"""
9+
10+
@initialize(invoke_without_command=True)
11+
def init(self):
12+
assert isinstance(self, Command)
13+
return "inheritance2_1::init()"
14+
15+
@command()
16+
def a(self):
17+
assert isinstance(self, Command)
18+
return "inheritance2_1::a()"
19+
20+
@command()
21+
def b(self):
22+
assert isinstance(self, Command)
23+
return "inheritance2_1::b()"
24+
25+
@group()
26+
def g(self):
27+
assert isinstance(self, Command)
28+
return "inheritance2_1::g()"
29+
30+
@g.command()
31+
def ga(self):
32+
assert isinstance(self, Command)
33+
return "inheritance2_1::g::ga()"
34+
35+
@g.command()
36+
def gb(self):
37+
assert isinstance(self, Command)
38+
return "inheritance2_1::g::gb()"
39+
40+
@g.command()
41+
def gc(self):
42+
assert isinstance(self, Command)
43+
return "inheritance2_1::g::gc()"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from django_typer.management import TyperCommand, command, group, initialize
2+
from .inheritance1 import Command as Inheritance1Command
3+
4+
5+
class Command(Inheritance1Command):
6+
"""
7+
Inheritance2_2
8+
"""
9+
10+
@initialize(invoke_without_command=True)
11+
def init(self):
12+
assert isinstance(self, Command)
13+
return "inheritance2_2::init()"
14+
15+
@command()
16+
def a(self):
17+
assert isinstance(self, Command)
18+
return "inheritance2_2::a()"
19+
20+
@command()
21+
def b(self):
22+
assert isinstance(self, Command)
23+
return "inheritance2_2::b()"
24+
25+
@command()
26+
def c(self):
27+
assert isinstance(self, Command)
28+
return "inheritance2_2::c()"
29+
30+
@group()
31+
def g(self):
32+
assert isinstance(self, Command)
33+
return "inheritance2_2::g()"
34+
35+
@g.command()
36+
def ga(self):
37+
assert isinstance(self, Command)
38+
return "inheritance2_2::g::ga()"
39+
40+
@group(invoke_without_command=True)
41+
def g2(self):
42+
assert isinstance(self, Command)
43+
return "inheritance2_2::g2()"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from django_typer.management import TyperCommand, command, group, initialize
2+
from .inheritance2_1 import Command as Inheritance21Command
3+
from .inheritance2_2 import Command as Inheritance22Command
4+
5+
6+
class Command(Inheritance21Command, Inheritance22Command):
7+
@command()
8+
def b(self):
9+
assert isinstance(self, Command)
10+
return "inheritance3::b()"
11+
12+
@command()
13+
def d(self):
14+
assert isinstance(self, Command)
15+
return "inheritance3::d()"
16+
17+
@Inheritance22Command.g2.command()
18+
def g2a(self):
19+
assert isinstance(self, Command)
20+
return "inheritance3::g2::g2a()"

tests/test_inheritance.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,64 @@ def test_handle_override(self):
2929
"class": "<class 'tests.apps.test_app.management.commands.help_precedence16.Command'>",
3030
},
3131
)
32+
33+
34+
class TestDiamondInheritance(TestCase):
35+
"""
36+
Multiple inheritance works!! Even diamond inheritance!
37+
"""
38+
39+
def test_diamond_inheritance_run(self):
40+
stdout, _, retcode = run_command("inheritance3")
41+
self.assertEqual(retcode, 0)
42+
self.assertTrue("inheritance2_1::init()" in stdout)
43+
44+
stdout, _, retcode = run_command("inheritance3", "a")
45+
self.assertEqual(retcode, 0)
46+
self.assertTrue("inheritance2_1::a()" in stdout)
47+
48+
stdout, _, retcode = run_command("inheritance2_2", "a")
49+
self.assertEqual(retcode, 0)
50+
self.assertTrue("inheritance2_2::a()" in stdout)
51+
52+
stdout, _, retcode = run_command("inheritance3", "b")
53+
self.assertEqual(retcode, 0)
54+
self.assertTrue("inheritance3::b()" in stdout)
55+
56+
stdout, _, retcode = run_command("inheritance3", "c")
57+
self.assertEqual(retcode, 0)
58+
self.assertTrue("inheritance2_2::c()" in stdout)
59+
60+
stdout, _, retcode = run_command("inheritance3", "g2", "g2a")
61+
self.assertEqual(retcode, 0)
62+
self.assertTrue("inheritance3::g2::g2a()" in stdout)
63+
64+
stdout, _, retcode = run_command("inheritance1", "g")
65+
self.assertEqual(retcode, 0)
66+
self.assertTrue("inheritance1::g()" in stdout)
67+
68+
stdout, _, retcode = run_command("inheritance3", "g")
69+
self.assertGreater(retcode, 0)
70+
71+
stdout, _, retcode = run_command("inheritance3", "g", "ga")
72+
self.assertEqual(retcode, 0)
73+
self.assertTrue("inheritance2_1::g::ga()" in stdout)
74+
75+
stdout, _, retcode = run_command("inheritance3", "g", "gb")
76+
self.assertEqual(retcode, 0)
77+
self.assertTrue("inheritance2_1::g::gb()" in stdout)
78+
79+
stdout, _, retcode = run_command("inheritance3", "g", "gc")
80+
self.assertEqual(retcode, 0)
81+
self.assertTrue("inheritance2_1::g::gc()" in stdout)
82+
83+
stdout, _, retcode = run_command("inheritance1", "g", "gc")
84+
self.assertGreater(retcode, 0)
85+
86+
stdout, _, retcode = run_command("inheritance1", "g", "ga")
87+
self.assertEqual(retcode, 0)
88+
self.assertTrue("inheritance1::g::ga()" in stdout)
89+
90+
stdout, _, retcode = run_command("inheritance1", "g", "gb")
91+
self.assertEqual(retcode, 0)
92+
self.assertTrue("inheritance1::g::gb()" in stdout)

0 commit comments

Comments
 (0)