2020Tests for the data files.
2121"""
2222
23+ import sys
2324import unittest
2425import tempfile
2526import os .path
@@ -42,10 +43,16 @@ class DataContainerMixin(object):
4243 Common tests for the the data container classes."
4344 """
4445 def test_load (self ):
45- self .assertRaises (IsADirectoryError , self .tested_class .load , "/" )
4646 self .assertRaises (
4747 FileNotFoundError , self .tested_class .load , "/file/does/not/exist" )
48- bad_format_files = ["LICENSE" , "/dev/urandom" ]
48+ if sys .platform != "win32" :
49+ self .assertRaises (IsADirectoryError , self .tested_class .load , "/" )
50+ bad_format_files = ["LICENSE" , "/dev/urandom" ]
51+ else :
52+ # Windows raises a PermissionError not IsADirectoryError when opening a dir
53+ self .assertRaises (PermissionError , self .tested_class .load , "/" )
54+ # No /dev/urandom on Windows
55+ bad_format_files = ["LICENSE" ]
4956 for bad_format_file in bad_format_files :
5057 self .assertTrue (os .path .exists (bad_format_file ))
5158 self .assertRaises (
@@ -98,6 +105,8 @@ def verify_data_round_trip(self, ts, input_file):
98105 the_age = ts .node (variant .site .mutations [0 ].node ).time
99106 self .assertEqual (the_age , age [j ])
100107
108+ @unittest .skipIf (sys .platform == "win32" ,
109+ "windows simultaneous file permissions issue" )
101110 def test_defaults_with_path (self ):
102111 ts = self .get_example_ts (10 , 10 )
103112 with tempfile .TemporaryDirectory (prefix = "tsinf_format_test" ) as tempdir :
@@ -137,6 +146,8 @@ def test_chunk_size(self):
137146 if name .endswith ("genotypes" ):
138147 self .assertEqual (array .chunks [1 ], chunk_size )
139148
149+ @unittest .skipIf (sys .platform == "win32" ,
150+ "windows simultaneous file permissions issue" )
140151 def test_filename (self ):
141152 ts = self .get_example_ts (14 , 15 )
142153 with tempfile .TemporaryDirectory (prefix = "tsinf_format_test" ) as tempdir :
@@ -150,6 +161,8 @@ def test_filename(self):
150161 self .assertIsNot (other_input_file , input_file )
151162 self .assertEqual (other_input_file , input_file )
152163
164+ @unittest .skipIf (sys .platform == "win32" ,
165+ "windows simultaneous file permissions issue" )
153166 def test_chunk_size_file_equal (self ):
154167 ts = self .get_example_ts (13 , 15 )
155168 with tempfile .TemporaryDirectory (prefix = "tsinf_format_test" ) as tempdir :
@@ -640,6 +653,8 @@ def test_copy_new_uuid(self):
640653 self .assertNotEqual (copy .uuid , data .uuid )
641654 self .assertTrue (copy .data_equal (data ))
642655
656+ @unittest .skipIf (sys .platform == "win32" ,
657+ "windows simultaneous file permissions issue" )
643658 def test_copy_update_inference_sites (self ):
644659 with formats .SampleData () as data :
645660 for j in range (4 ):
@@ -687,6 +702,8 @@ def set_value(data, value):
687702 data .finalise ()
688703 self .assertRaises (ValueError , set_value , data , [])
689704
705+ @unittest .skipIf (sys .platform == "win32" ,
706+ "windows simultaneous file permissions issue" )
690707 def test_overwrite_partial (self ):
691708 # Check that we can correctly overwrite partially written and
692709 # unfinalised files. See
@@ -791,6 +808,8 @@ def test_defaults_no_path(self):
791808 for _ , array in ancestor_data .arrays ():
792809 self .assertEqual (array .compressor , None )
793810
811+ @unittest .skipIf (sys .platform == "win32" ,
812+ "windows simultaneous file permissions issue" )
794813 def test_defaults_with_path (self ):
795814 sample_data , ancestors = self .get_example_data (10 , 10 , 40 )
796815 with tempfile .TemporaryDirectory (prefix = "tsinf_format_test" ) as tempdir :
@@ -835,6 +854,8 @@ def test_chunk_size(self):
835854 self .assertEqual (ancestor_data .ancestors_end .chunks , (chunk_size ,))
836855 self .assertEqual (ancestor_data .ancestors_age .chunks , (chunk_size ,))
837856
857+ @unittest .skipIf (sys .platform == "win32" ,
858+ "windows simultaneous file permissions issue" )
838859 def test_filename (self ):
839860 sample_data , ancestors = self .get_example_data (10 , 2 , 40 )
840861 with tempfile .TemporaryDirectory (prefix = "tsinf_format_test" ) as tempdir :
@@ -848,6 +869,8 @@ def test_filename(self):
848869 self .assertIsNot (other_ancestor_data , ancestor_data )
849870 self .assertEqual (other_ancestor_data , ancestor_data )
850871
872+ @unittest .skipIf (sys .platform == "win32" ,
873+ "windows simultaneous file permissions issue" )
851874 def test_chunk_size_file_equal (self ):
852875 N = 60
853876 sample_data , ancestors = self .get_example_data (22 , 16 , N )
@@ -910,6 +933,8 @@ def test_add_ancestor_errors(self):
910933 start = 0 , end = num_sites , age = 1 , focal_sites = [0 ],
911934 haplotype = np .zeros (num_sites , dtype = np .uint8 ))
912935
936+ @unittest .skipIf (sys .platform == "win32" ,
937+ "windows simultaneous file permissions issue" )
913938 def test_zero_sequence_length (self ):
914939 # Mangle a sample data file to force a zero sequence length.
915940 ts = msprime .simulate (10 , mutation_rate = 2 , random_seed = 5 )
0 commit comments