@@ -831,3 +831,55 @@ def test_create_with_missingness(self):
831831 patterns .add (p + b )
832832 # all pattern possibilities should be present
833833 self .assertSetEqual (patterns , {0 , 1 , 2 , 3 })
834+
835+
836+ class GeneratorTests (GeneratesDBTestCase ):
837+ """ Testing configure-missing with generation. """
838+ dump_file_path = "instrument.sql"
839+ database_name = "instrument"
840+ schema_name = "public"
841+
842+ def _get_cmd (self , config ) -> TestGeneratorCmd :
843+ return TestGeneratorCmd (self .dsn , self .schema_name , self .metadata , config )
844+
845+ def test_set_null (self ):
846+ """ Test that we can sample real missingness and reproduce it. """
847+ with self ._get_cmd ({}) as gc :
848+ gc .do_next ("string.position" )
849+ gc .do_set ("dist_gen.constant" )
850+ self .assertListEqual (gc .messages , [])
851+ gc .reset ()
852+ gc .do_next ("string.frequency" )
853+ gc .do_set ("dist_gen.constant" )
854+ self .assertListEqual (gc .messages , [])
855+ gc .reset ()
856+ gc .do_next ("signature_model.name" )
857+ gc .do_set ("dist_gen.constant" )
858+ self .assertListEqual (gc .messages , [])
859+ gc .reset ()
860+ gc .do_next ("signature_model.based_on" )
861+ gc .do_set ("dist_gen.constant" )
862+ # we have got to the end of the columns, but shouldn't have any errors
863+ self .assertListEqual (gc .messages , [("No more tables" , (), {})])
864+ gc .reset ()
865+ gc .do_quit ("" )
866+ config = gc .config
867+ self .generate_data (config , num_passes = 3 )
868+ # Test that each missingness pattern is present in the database
869+ with self .engine .connect () as conn :
870+ stmt = select (self .metadata .tables ["string" ].c ["position" , "frequency" ])
871+ rows = conn .execute (stmt ).fetchall ()
872+ count = 0
873+ for row in rows :
874+ count += 1
875+ self .assertEqual (row .position , 0 )
876+ self .assertEqual (row .frequency , 0.0 )
877+ self .assertEqual (count , 3 )
878+ stmt = select (self .metadata .tables ["signature_model" ].c ["name" , "based_on" ])
879+ rows = conn .execute (stmt ).fetchall ()
880+ count = 0
881+ for row in rows :
882+ count += 1
883+ self .assertEqual (row .name , "" )
884+ self .assertIsNone (row .based_on )
885+ self .assertEqual (count , 3 )
0 commit comments