1- from nose . tools import assert_false , assert_true , assert_equal , raises
1+ import pytest
22import datajoint as dj
33from .schema_simple import A , B , D , E , L , Website , Profile
44from .schema import ComplexChild , ComplexParent
55
66
7+ @pytest .fixture
8+ def schema_simp_pop (schema_simp ):
9+ A ().insert (A .contents , skip_duplicates = True )
10+ L ().insert (L .contents , skip_duplicates = True )
11+ B ().populate ()
12+ D ().populate ()
13+ E ().populate ()
14+ yield schema_simp
15+
16+
717class TestDelete :
8- @staticmethod
9- def setup ():
10- """
11- class-level test setup. Executes before each test method.
12- """
13- A ().insert (A .contents , skip_duplicates = True )
14- L ().insert (L .contents , skip_duplicates = True )
15- B ().populate ()
16- D ().populate ()
17- E ().populate ()
1818
19- @staticmethod
20- def test_delete_tree ():
21- assert_false (dj .config ["safemode" ], "safemode must be off for testing" )
22- assert_true (
19+ def test_delete_tree (self , schema_simp_pop ):
20+ assert not dj .config ["safemode" ], "safemode must be off for testing"
21+ assert (
2322 L () and A () and B () and B .C () and D () and E () and E .F (),
2423 "schema is not populated" ,
2524 )
2625 A ().delete ()
27- assert_false ( A () or B () or B .C () or D () or E () or E .F (), "incomplete delete" )
26+ assert not A () or B () or B .C () or D () or E () or E .F (), "incomplete delete"
2827
29- @staticmethod
30- def test_stepwise_delete ():
28+ def test_stepwise_delete (self , schema_simp_pop ):
3129 assert not dj .config ["safemode" ], "safemode must be off for testing"
3230 assert L () and A () and B () and B .C (), "schema population failed"
3331 B .C ().delete (force = True )
@@ -37,8 +35,7 @@ def test_stepwise_delete():
3735 not B ()
3836 ), "failed to delete from the parent table following child table deletion"
3937
40- @staticmethod
41- def test_delete_tree_restricted ():
38+ def test_delete_tree_restricted (self , schema_simp_pop ):
4239 assert not dj .config ["safemode" ], "safemode must be off for testing"
4340 assert (
4441 L () and A () and B () and B .C () and D () and E () and E .F ()
@@ -64,35 +61,34 @@ def test_delete_tree_restricted():
6461 assert len (E ()) == rest ["E" ], "invalid delete restriction"
6562 assert len (E .F ()) == rest ["F" ], "invalid delete restriction"
6663
67- @staticmethod
68- def test_delete_lookup ():
69- assert_false (dj .config ["safemode" ], "safemode must be off for testing" )
70- assert_true (
64+ def test_delete_lookup (self , schema_simp_pop ):
65+ assert not dj .config ["safemode" ], "safemode must be off for testing"
66+ assert (
7167 bool (L () and A () and B () and B .C () and D () and E () and E .F ()),
7268 "schema is not populated" ,
7369 )
7470 L ().delete ()
75- assert_false ( bool (L () or D () or E () or E .F ()), "incomplete delete" )
71+ assert not bool (L () or D () or E () or E .F ()), "incomplete delete"
7672 A ().delete () # delete all is necessary because delete L deletes from subtables.
7773
78- @staticmethod
79- def test_delete_lookup_restricted ():
80- assert_false (dj .config ["safemode" ], "safemode must be off for testing" )
81- assert_true (
74+ def test_delete_lookup_restricted (self , schema_simp_pop ):
75+ assert not dj .config ["safemode" ], "safemode must be off for testing"
76+ assert (
8277 L () and A () and B () and B .C () and D () and E () and E .F (),
8378 "schema is not populated" ,
8479 )
8580 rel = L () & "cond_in_l"
8681 original_count = len (L ())
8782 deleted_count = len (rel )
8883 rel .delete ()
89- assert_true ( len (L ()) == original_count - deleted_count )
84+ assert len (L ()) == original_count - deleted_count
9085
91- @staticmethod
92- def test_delete_complex_keys ():
93- # https://github.com/datajoint/datajoint-python/issues/883
94- # https://github.com/datajoint/datajoint-python/issues/886
95- assert_false (dj .config ["safemode" ], "safemode must be off for testing" )
86+ def test_delete_complex_keys (self , schema_any ):
87+ """
88+ https://github.com/datajoint/datajoint-python/issues/883
89+ https://github.com/datajoint/datajoint-python/issues/886
90+ """
91+ assert not dj .config ["safemode" ], "safemode must be off for testing"
9692 parent_key_count = 8
9793 child_key_count = 1
9894 restriction = dict (
@@ -108,17 +104,17 @@ def test_delete_complex_keys():
108104 assert len (ComplexParent & restriction ) == 0 , "Parent record was not deleted"
109105 assert len (ComplexChild & restriction ) == 0 , "Child record was not deleted"
110106
111- def test_delete_master (self ):
107+ def test_delete_master (self , schema_simp_pop ):
112108 Profile ().populate_random ()
113109 Profile ().delete ()
114110
115- @raises (dj .DataJointError )
116- def test_delete_parts (self ):
111+ def test_delete_parts (self , schema_simp_pop ):
117112 """test issue #151"""
118- Profile ().populate_random ()
119- Website ().delete ()
113+ with pytest .raises (dj .DataJointError ):
114+ Profile ().populate_random ()
115+ Website ().delete ()
120116
121- @raises (dj .DataJointError )
122- def test_drop_part (self ):
117+ def test_drop_part (self , schema_simp_pop ):
123118 """test issue #374"""
124- Website ().drop ()
119+ with pytest .raises (dj .DataJointError ):
120+ Website ().drop ()
0 commit comments