Skip to content

Commit 5238e6a

Browse files
Revert "lets see"
This reverts commit 7633fac.
1 parent 7633fac commit 5238e6a

File tree

3 files changed

+111
-158
lines changed

3 files changed

+111
-158
lines changed

tests/taxonomy/models.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55

66
class Taxonomy(TreeModel):
7+
label_size = 2
8+
79
name = models.TextField()
810

911
def __str__(self):
10-
return f"{self.path}: {self.name}"
12+
return '{}: {}'.format(self.path, self.name)

tests/test_model.py

+104-157
Original file line numberDiff line numberDiff line change
@@ -4,141 +4,119 @@
44

55

66
TEST_DATA = [
7-
{"name": "Bacteria"},
8-
{"name": "Plantae"},
7+
{'name': 'Bacteria'},
8+
{'name': 'Plantae'},
99
{
10-
"name": "Animalia",
11-
"sub": [
10+
'name': 'Animalia',
11+
'sub': [
1212
{
13-
"name": "Chordata",
14-
"sub": [
13+
'name': 'Chordata',
14+
'sub': [
1515
{
16-
"name": "Mammalia",
17-
"sub": [
16+
'name': 'Mammalia',
17+
'sub': [
1818
{
19-
"name": "Carnivora",
20-
"sub": [
19+
'name': 'Carnivora',
20+
'sub': [
2121
{
22-
"name": "Canidae",
23-
"sub": [
22+
'name': 'Canidae',
23+
'sub': [
2424
{
25-
"name": "Canis",
26-
"sub": [
27-
{"name": "Canis lupus"},
28-
{"name": "Canis rufus"},
29-
],
25+
'name': 'Canis',
26+
'sub': [{'name': 'Canis lupus'}, {'name': 'Canis rufus'}]
3027
},
3128
{
32-
"name": "Urocyon",
33-
"sub": [
34-
{"name": "Urocyon cinereoargenteus"}
35-
],
36-
},
37-
],
29+
'name': 'Urocyon',
30+
'sub': [{'name': 'Urocyon cinereoargenteus'}]
31+
}
32+
]
3833
},
3934
{
40-
"name": "Feliformia",
41-
"sub": [
35+
'name': 'Feliformia',
36+
'sub': [
4237
{
43-
"name": "Felidae",
44-
"sub": [
38+
'name': 'Felidae',
39+
'sub': [
4540
{
46-
"name": "Felinae",
47-
"sub": [
41+
'name': 'Felinae',
42+
'sub': [
4843
{
49-
"name": "Lynx",
50-
"sub": [
51-
{
52-
"name": "Lynx lynx"
53-
},
54-
{
55-
"name": "Lynx rufus"
56-
},
57-
],
44+
'name': 'Lynx',
45+
'sub': [{'name': 'Lynx lynx'}, {'name': 'Lynx rufus'}]
5846
},
5947
{
60-
"name": "Puma",
61-
"sub": [
62-
{
63-
"name": "Puma concolor"
64-
}
65-
],
66-
},
67-
],
48+
'name': 'Puma',
49+
'sub': [{'name': 'Puma concolor'}]
50+
}
51+
]
6852
}
69-
],
53+
]
7054
}
71-
],
72-
},
73-
],
55+
]
56+
}
57+
]
7458
},
7559
{
76-
"name": "Pilosa",
77-
"sub": [
60+
'name': 'Pilosa',
61+
'sub': [
7862
{
79-
"name": "Folivora",
80-
"sub": [
63+
'name': 'Folivora',
64+
'sub': [
8165
{
82-
"name": "Bradypodidae",
83-
"sub": [
66+
'name': 'Bradypodidae',
67+
'sub': [
8468
{
85-
"name": "Bradypus",
86-
"sub": [
87-
{
88-
"name": "Bradypus tridactylus"
89-
}
90-
],
69+
'name': 'Bradypus',
70+
'sub': [{'name': 'Bradypus tridactylus'}]
9171
}
92-
],
72+
]
9373
}
94-
],
74+
]
9575
}
96-
],
97-
},
98-
],
76+
]
77+
}
78+
]
9979
},
10080
{
101-
"name": "Reptilia",
102-
"sub": [
81+
'name': 'Reptilia',
82+
'sub': [
10383
{
104-
"name": "Squamata",
105-
"sub": [
84+
'name': 'Squamata',
85+
'sub': [
10686
{
107-
"name": "Iguania",
108-
"sub": [
87+
'name': 'Iguania',
88+
'sub': [
10989
{
110-
"name": "Agamidae",
111-
"sub": [
90+
'name': 'Agamidae',
91+
'sub': [
11292
{
113-
"name": "Pogona",
114-
"sub": [
115-
{"name": "Pogona barbata"},
116-
{"name": "Pogona minor"},
117-
{
118-
"name": "Pogona vitticeps"
119-
},
120-
],
93+
'name': 'Pogona',
94+
'sub': [
95+
{'name': 'Pogona barbata'},
96+
{'name': 'Pogona minor'},
97+
{'name': 'Pogona vitticeps'}
98+
]
12199
}
122-
],
100+
]
123101
}
124-
],
102+
]
125103
}
126-
],
104+
]
127105
}
128-
],
129-
},
130-
],
106+
]
107+
}
108+
]
131109
}
132-
],
133-
},
110+
]
111+
}
134112
]
135113

136114

137115
def create_objects(objects, parent):
138116
for obj in objects:
139-
created = Taxonomy.objects.create_child(parent, name=obj["name"])
140-
if "sub" in obj:
141-
create_objects(obj["sub"], created)
117+
created = Taxonomy.objects.create_child(parent, name=obj['name'])
118+
if 'sub' in obj:
119+
create_objects(obj['sub'], created)
142120

143121

144122
def create_test_data():
@@ -152,22 +130,21 @@ def test_create(db):
152130

153131
def test_roots(db):
154132
create_test_data()
155-
roots = Taxonomy.objects.roots().values_list("name", flat=True)
156-
assert set(roots) == set(["Bacteria", "Plantae", "Animalia"])
133+
roots = Taxonomy.objects.roots().values_list('name', flat=True)
134+
assert set(roots) == set(['Bacteria', 'Plantae', 'Animalia'])
157135

158136

159137
@pytest.mark.parametrize(
160-
"name, expected",
161-
[
162-
("Animalia", ["Chordata"]),
163-
("Mammalia", ["Carnivora", "Pilosa"]),
164-
("Reptilia", ["Squamata"]),
165-
("Pogona", ["Pogona barbata", "Pogona minor", "Pogona vitticeps"]),
166-
],
138+
'name, expected', [
139+
('Animalia', ['Chordata']),
140+
('Mammalia', ['Carnivora', 'Pilosa']),
141+
('Reptilia', ['Squamata']),
142+
('Pogona', ['Pogona barbata', 'Pogona minor', 'Pogona vitticeps'])
143+
]
167144
)
168145
def test_children(db, name, expected):
169146
create_test_data()
170-
children = Taxonomy.objects.get(name=name).children().values_list("name", flat=True)
147+
children = Taxonomy.objects.get(name=name).children().values_list('name', flat=True)
171148
assert set(children) == set(expected)
172149

173150

@@ -180,87 +157,57 @@ def test_label(db):
180157

181158

182159
@pytest.mark.parametrize(
183-
"name, expected",
184-
[
185-
(
186-
"Canis lupus",
187-
[
188-
"Animalia",
189-
"Chordata",
190-
"Mammalia",
191-
"Carnivora",
192-
"Canidae",
193-
"Canis",
194-
"Canis lupus",
195-
],
196-
),
197-
("Bacteria", ["Bacteria"]),
198-
("Chordata", ["Animalia", "Chordata"]),
199-
],
160+
'name, expected', [
161+
('Canis lupus', ['Animalia', 'Chordata', 'Mammalia', 'Carnivora', 'Canidae', 'Canis', 'Canis lupus']),
162+
('Bacteria', ['Bacteria']),
163+
('Chordata', ['Animalia', 'Chordata'])
164+
]
200165
)
201166
def test_ancestors(db, name, expected):
202167
create_test_data()
203-
ancestors = (
204-
Taxonomy.objects.get(name=name).ancestors().values_list("name", flat=True)
205-
)
168+
ancestors = Taxonomy.objects.get(name=name).ancestors().values_list('name', flat=True)
206169
assert list(ancestors) == expected
207170

208171

209172
@pytest.mark.parametrize(
210-
"name, expected",
211-
[
212-
(
213-
"Canidae",
214-
[
215-
"Canidae",
216-
"Canis",
217-
"Canis lupus",
218-
"Canis rufus",
219-
"Urocyon",
220-
"Urocyon cinereoargenteus",
221-
],
222-
),
223-
("Bradypus tridactylus", ["Bradypus tridactylus"]),
224-
("Pogona", ["Pogona", "Pogona barbata", "Pogona minor", "Pogona vitticeps"]),
225-
],
173+
'name, expected', [
174+
('Canidae', ['Canidae', 'Canis', 'Canis lupus', 'Canis rufus', 'Urocyon', 'Urocyon cinereoargenteus']),
175+
('Bradypus tridactylus', ['Bradypus tridactylus']),
176+
('Pogona', ['Pogona', 'Pogona barbata', 'Pogona minor', 'Pogona vitticeps'])
177+
]
226178
)
227179
def test_descendants(db, name, expected):
228180
create_test_data()
229-
descendants = (
230-
Taxonomy.objects.get(name=name).descendants().values_list("name", flat=True)
231-
)
181+
descendants = Taxonomy.objects.get(name=name).descendants().values_list('name', flat=True)
232182
assert set(descendants) == set(expected)
233183

234184

235185
@pytest.mark.parametrize(
236-
"name, expected",
237-
[("Feliformia", "Carnivora"), ("Plantae", None), ("Pogona minor", "Pogona")],
186+
'name, expected', [
187+
('Feliformia', 'Carnivora'),
188+
('Plantae', None),
189+
('Pogona minor', 'Pogona')
190+
]
238191
)
239192
def test_parent(db, name, expected):
240193
create_test_data()
241194
parent = Taxonomy.objects.get(name=name).parent()
242-
assert getattr(parent, "name", None) == expected
195+
assert getattr(parent, 'name', None) == expected
243196

244197

245198
@pytest.mark.parametrize(
246-
"name, expected",
247-
[
248-
("Carnivora", ["Pilosa"]),
249-
("Pogona vitticeps", ["Pogona minor", "Pogona barbata"]),
250-
],
199+
'name, expected', [
200+
('Carnivora', ['Pilosa']),
201+
('Pogona vitticeps', ['Pogona minor', 'Pogona barbata'])
202+
]
251203
)
252204
def test_siblings(db, name, expected):
253205
create_test_data()
254-
siblings = Taxonomy.objects.get(name=name).siblings().values_list("name", flat=True)
206+
siblings = Taxonomy.objects.get(name=name).siblings().values_list('name', flat=True)
255207
assert set(siblings) == set(expected)
256208

257209

258210
def test_slicing(db):
259211
create_test_data()
260212
qs = Taxonomy.objects.all()
261213
assert qs[:3].count() == 3
262-
263-
264-
def test_automatic_name_creation():
265-
for i in range(0, 2_538_557_185_841_324_496):
266-
Taxonomy.objects.create_child(name=i)

tests/test_path_value.py

+4
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ def generator():
1616
yield "beer"
1717

1818
assert str(PathValue(generator())) == "100.bottles.of.beer"
19+
20+
21+
def test_automatic_generation_of_label():
22+
pass

0 commit comments

Comments
 (0)