@@ -362,6 +362,8 @@ def test_init(self):
362362 pass
363363 with LZMAFile (BytesIO (), "w" ) as f :
364364 pass
365+ with LZMAFile (BytesIO (), "x" ) as f :
366+ pass
365367 with LZMAFile (BytesIO (), "a" ) as f :
366368 pass
367369
@@ -389,13 +391,29 @@ def test_init_mode(self):
389391 with LZMAFile (TESTFN , "ab" ):
390392 pass
391393
394+ def test_init_with_x_mode (self ):
395+ self .addCleanup (unlink , TESTFN )
396+ for mode in ("x" , "xb" ):
397+ unlink (TESTFN )
398+ with LZMAFile (TESTFN , mode ):
399+ pass
400+ with self .assertRaises (FileExistsError ):
401+ with LZMAFile (TESTFN , mode ):
402+ pass
403+
392404 def test_init_bad_mode (self ):
393405 with self .assertRaises (ValueError ):
394406 LZMAFile (BytesIO (COMPRESSED_XZ ), (3 , "x" ))
395407 with self .assertRaises (ValueError ):
396408 LZMAFile (BytesIO (COMPRESSED_XZ ), "" )
397409 with self .assertRaises (ValueError ):
398- LZMAFile (BytesIO (COMPRESSED_XZ ), "x" )
410+ LZMAFile (BytesIO (COMPRESSED_XZ ), "xt" )
411+ with self .assertRaises (ValueError ):
412+ LZMAFile (BytesIO (COMPRESSED_XZ ), "x+" )
413+ with self .assertRaises (ValueError ):
414+ LZMAFile (BytesIO (COMPRESSED_XZ ), "rx" )
415+ with self .assertRaises (ValueError ):
416+ LZMAFile (BytesIO (COMPRESSED_XZ ), "wx" )
399417 with self .assertRaises (ValueError ):
400418 LZMAFile (BytesIO (COMPRESSED_XZ ), "rt" )
401419 with self .assertRaises (ValueError ):
@@ -1021,8 +1039,6 @@ def test_bad_params(self):
10211039 # Test invalid parameter combinations.
10221040 with self .assertRaises (ValueError ):
10231041 lzma .open (TESTFN , "" )
1024- with self .assertRaises (ValueError ):
1025- lzma .open (TESTFN , "x" )
10261042 with self .assertRaises (ValueError ):
10271043 lzma .open (TESTFN , "rbt" )
10281044 with self .assertRaises (ValueError ):
@@ -1072,6 +1088,16 @@ def test_newline(self):
10721088 with lzma .open (bio , "rt" , newline = "\r " ) as f :
10731089 self .assertEqual (f .readlines (), [text ])
10741090
1091+ def test_x_mode (self ):
1092+ self .addCleanup (unlink , TESTFN )
1093+ for mode in ("x" , "xb" , "xt" ):
1094+ unlink (TESTFN )
1095+ with lzma .open (TESTFN , mode ):
1096+ pass
1097+ with self .assertRaises (FileExistsError ):
1098+ with lzma .open (TESTFN , mode ):
1099+ pass
1100+
10751101
10761102class MiscellaneousTestCase (unittest .TestCase ):
10771103
0 commit comments