@@ -1505,14 +1505,15 @@ class TestArgumentsFromFile(TempDirMixin, ParserTestCase):
1505
1505
def setUp (self ):
1506
1506
super (TestArgumentsFromFile , self ).setUp ()
1507
1507
file_texts = [
1508
- ('hello' , 'hello world!\n ' ),
1509
- ('recursive' , '-a\n '
1510
- 'A\n '
1511
- '@hello' ),
1512
- ('invalid' , '@no-such-path\n ' ),
1508
+ ('hello' , os .fsencode (self .hello ) + b'\n ' ),
1509
+ ('recursive' , b'-a\n '
1510
+ b'A\n '
1511
+ b'@hello' ),
1512
+ ('invalid' , b'@no-such-path\n ' ),
1513
+ ('undecodable' , self .undecodable + b'\n ' ),
1513
1514
]
1514
1515
for path , text in file_texts :
1515
- with open (path , 'w' , encoding = "utf-8" ) as file :
1516
+ with open (path , 'wb' ) as file :
1516
1517
file .write (text )
1517
1518
1518
1519
parser_signature = Sig (fromfile_prefix_chars = '@' )
@@ -1522,15 +1523,25 @@ def setUp(self):
1522
1523
Sig ('y' , nargs = '+' ),
1523
1524
]
1524
1525
failures = ['' , '-b' , 'X' , '@invalid' , '@missing' ]
1526
+ hello = 'hello world!' + os_helper .FS_NONASCII
1525
1527
successes = [
1526
1528
('X Y' , NS (a = None , x = 'X' , y = ['Y' ])),
1527
1529
('X -a A Y Z' , NS (a = 'A' , x = 'X' , y = ['Y' , 'Z' ])),
1528
- ('@hello X' , NS (a = None , x = ' hello world!' , y = ['X' ])),
1529
- ('X @hello' , NS (a = None , x = 'X' , y = [' hello world!' ])),
1530
- ('-a B @recursive Y Z' , NS (a = 'A' , x = ' hello world!' , y = ['Y' , 'Z' ])),
1531
- ('X @recursive Z -a B' , NS (a = 'B' , x = 'X' , y = [' hello world!' , 'Z' ])),
1530
+ ('@hello X' , NS (a = None , x = hello , y = ['X' ])),
1531
+ ('X @hello' , NS (a = None , x = 'X' , y = [hello ])),
1532
+ ('-a B @recursive Y Z' , NS (a = 'A' , x = hello , y = ['Y' , 'Z' ])),
1533
+ ('X @recursive Z -a B' , NS (a = 'B' , x = 'X' , y = [hello , 'Z' ])),
1532
1534
(["-a" , "" , "X" , "Y" ], NS (a = '' , x = 'X' , y = ['Y' ])),
1533
1535
]
1536
+ if os_helper .TESTFN_UNDECODABLE :
1537
+ undecodable = os_helper .TESTFN_UNDECODABLE .lstrip (b'@' )
1538
+ decoded_undecodable = os .fsdecode (undecodable )
1539
+ successes += [
1540
+ ('@undecodable X' , NS (a = None , x = decoded_undecodable , y = ['X' ])),
1541
+ ('X @undecodable' , NS (a = None , x = 'X' , y = [decoded_undecodable ])),
1542
+ ]
1543
+ else :
1544
+ undecodable = b''
1534
1545
1535
1546
1536
1547
class TestArgumentsFromFileConverter (TempDirMixin , ParserTestCase ):
@@ -1539,10 +1550,10 @@ class TestArgumentsFromFileConverter(TempDirMixin, ParserTestCase):
1539
1550
def setUp (self ):
1540
1551
super (TestArgumentsFromFileConverter , self ).setUp ()
1541
1552
file_texts = [
1542
- ('hello' , 'hello world!\n ' ),
1553
+ ('hello' , b 'hello world!\n ' ),
1543
1554
]
1544
1555
for path , text in file_texts :
1545
- with open (path , 'w' , encoding = "utf-8" ) as file :
1556
+ with open (path , 'wb' ) as file :
1546
1557
file .write (text )
1547
1558
1548
1559
class FromFileConverterArgumentParser (ErrorRaisingArgumentParser ):
0 commit comments