Test reading arguments from a file
| 1809 | |
| 1810 | |
| 1811 | class TestArgumentsFromFile(TempDirMixin, ParserTestCase): |
| 1812 | """Test reading arguments from a file""" |
| 1813 | |
| 1814 | def setUp(self): |
| 1815 | super(TestArgumentsFromFile, self).setUp() |
| 1816 | file_texts = [ |
| 1817 | ('hello', os.fsencode(self.hello) + b'\n'), |
| 1818 | ('recursive', b'-a\n' |
| 1819 | b'A\n' |
| 1820 | b'@hello'), |
| 1821 | ('invalid', b'@no-such-path\n'), |
| 1822 | ('undecodable', self.undecodable + b'\n'), |
| 1823 | ] |
| 1824 | for path, text in file_texts: |
| 1825 | with open(path, 'wb') as file: |
| 1826 | file.write(text) |
| 1827 | |
| 1828 | parser_signature = Sig(fromfile_prefix_chars='@') |
| 1829 | argument_signatures = [ |
| 1830 | Sig('-a'), |
| 1831 | Sig('x'), |
| 1832 | Sig('y', nargs='+'), |
| 1833 | ] |
| 1834 | failures = ['', '-b', 'X', '@invalid', '@missing'] |
| 1835 | hello = 'hello world!' + os_helper.FS_NONASCII |
| 1836 | successes = [ |
| 1837 | ('X Y', NS(a=None, x='X', y=['Y'])), |
| 1838 | ('X -a A Y Z', NS(a='A', x='X', y=['Y', 'Z'])), |
| 1839 | ('@hello X', NS(a=None, x=hello, y=['X'])), |
| 1840 | ('X @hello', NS(a=None, x='X', y=[hello])), |
| 1841 | ('-a B @recursive Y Z', NS(a='A', x=hello, y=['Y', 'Z'])), |
| 1842 | ('X @recursive Z -a B', NS(a='B', x='X', y=[hello, 'Z'])), |
| 1843 | (["-a", "", "X", "Y"], NS(a='', x='X', y=['Y'])), |
| 1844 | ] |
| 1845 | if os_helper.TESTFN_UNDECODABLE: |
| 1846 | undecodable = os_helper.TESTFN_UNDECODABLE.lstrip(b'@') |
| 1847 | decoded_undecodable = os.fsdecode(undecodable) |
| 1848 | successes += [ |
| 1849 | ('@undecodable X', NS(a=None, x=decoded_undecodable, y=['X'])), |
| 1850 | ('X @undecodable', NS(a=None, x='X', y=[decoded_undecodable])), |
| 1851 | ] |
| 1852 | else: |
| 1853 | undecodable = b'' |
| 1854 | |
| 1855 | |
| 1856 | class TestArgumentsFromFileConverter(TempDirMixin, ParserTestCase): |