@@ -2692,6 +2692,104 @@ def test_impute_unknown_mutations_time(self, ts):
26922692 ):
26932693 ts .impute_unknown_mutations_time (method = "foobar" )
26942694
2695+ @pytest .mark .parametrize (
2696+ "mutations, error" ,
2697+ [
2698+ ([], None ),
2699+ (
2700+ [{"node" : 0 , "parent" : - 1 }, {"node" : 1 , "parent" : - 1 }],
2701+ None ,
2702+ ), # On parallel branches, no parents
2703+ (
2704+ [
2705+ {"node" : 4 , "parent" : - 1 },
2706+ {"node" : 0 , "parent" : 0 },
2707+ {"node" : 1 , "parent" : 0 },
2708+ ],
2709+ None ,
2710+ ), # On parallel branches, legal parent
2711+ (
2712+ [{"node" : 0 , "parent" : - 1 }, {"node" : 0 , "parent" : 0 }],
2713+ None ,
2714+ ), # On same node
2715+ (
2716+ [{"node" : 0 , "parent" : - 1 }, {"node" : 0 , "parent" : - 1 }],
2717+ "not consistent with the topology" ,
2718+ ), # On same node without parents
2719+ (
2720+ [
2721+ {"node" : 3 , "parent" : - 1 },
2722+ {"node" : 0 , "parent" : 0 },
2723+ {"node" : 1 , "parent" : 0 },
2724+ ],
2725+ "not consistent with the topology" ,
2726+ ), # On parallel branches, parent on parallel branches
2727+ (
2728+ [
2729+ {"node" : 5 , "parent" : - 1 },
2730+ {"node" : 0 , "parent" : 0 },
2731+ {"node" : 1 , "parent" : 0 },
2732+ ],
2733+ "not consistent with the topology" ,
2734+ ), # On parallel branches, parent high on parallel
2735+ (
2736+ [
2737+ {"node" : 3 , "parent" : - 1 },
2738+ {"node" : 0 , "parent" : 0 },
2739+ {"node" : 7 , "parent" : 0 },
2740+ ],
2741+ "not consistent with the topology" ,
2742+ ), # On parallel branches, parent on different root
2743+ (
2744+ [
2745+ {"node" : 0 , "parent" : - 1 },
2746+ {"node" : 1 , "parent" : 0 },
2747+ ],
2748+ "not consistent with the topology" ,
2749+ ), # parent on parallel branch
2750+ (
2751+ [
2752+ {"node" : 6 , "parent" : - 1 },
2753+ {"node" : 6 , "parent" : 0 },
2754+ ],
2755+ None ,
2756+ ), # parent above root
2757+ (
2758+ [
2759+ {"node" : 6 , "parent" : - 1 },
2760+ {"node" : 6 , "parent" : - 1 },
2761+ ],
2762+ "not consistent with the topology" ,
2763+ ), # parent above root, no parents
2764+ ],
2765+ )
2766+ def test_mutation_parent_errors (self , mutations , error ):
2767+ tables = tskit .TableCollection (sequence_length = 1 )
2768+ tables .nodes .add_row (time = 0 , flags = tskit .NODE_IS_SAMPLE )
2769+ tables .nodes .add_row (time = 0 , flags = tskit .NODE_IS_SAMPLE )
2770+ tables .nodes .add_row (time = 0 , flags = tskit .NODE_IS_SAMPLE )
2771+ tables .nodes .add_row (time = 0 , flags = tskit .NODE_IS_SAMPLE )
2772+ tables .nodes .add_row (time = 1 )
2773+ tables .nodes .add_row (time = 1 )
2774+ tables .nodes .add_row (time = 2 )
2775+ tables .nodes .add_row (time = 3 )
2776+ tables .edges .add_row (left = 0 , right = 1 , parent = 4 , child = 0 )
2777+ tables .edges .add_row (left = 0 , right = 1 , parent = 4 , child = 1 )
2778+ tables .edges .add_row (left = 0 , right = 1 , parent = 5 , child = 2 )
2779+ tables .edges .add_row (left = 0 , right = 1 , parent = 5 , child = 3 )
2780+ tables .edges .add_row (left = 0 , right = 1 , parent = 6 , child = 4 )
2781+ tables .edges .add_row (left = 0 , right = 1 , parent = 6 , child = 5 )
2782+ tables .sites .add_row (position = 0.5 , ancestral_state = "A" )
2783+
2784+ for mut in mutations :
2785+ tables .mutations .add_row (** {"derived_state" : "G" , "site" : 0 , ** mut })
2786+
2787+ if error is not None :
2788+ with pytest .raises (_tskit .LibraryError , match = error ):
2789+ tables .tree_sequence ()
2790+ else :
2791+ tables .tree_sequence ()
2792+
26952793
26962794class TestSimplify :
26972795 # This class was factored out of the old TestHighlevel class 2022-12-13,
0 commit comments