def test_parse_out_path_valid(self): # Function should not affect valid length filenames and paths. normal_filename = 'document' parsedPath = ScraperUtils.parse_out_path('C:\\Example\\Path', normal_filename, 'pdf') assert parsedPath == os.path.join( 'C:\\Example\\Path', '{}.{}'.format(normal_filename, 'pdf'))
def test_parse_out_path_shortening(self): # 260 characters long before the extension. This is an invalid filename in Windows. filename_too_long = '01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789' parsed_path = ScraperUtils.parse_out_path(os.getcwd(), filename_too_long, 'txt') try: open(parsed_path, 'w') os.remove(parsed_path) except OSError: pytest.fail('parse_out_path() generates an invalid file path.')
def test_parse_out_path_correct_length(self): # 260 characters long before the extension. This is an invalid filename in Windows. filename_too_long = '01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789' parsed_path = ScraperUtils.parse_out_path(os.getcwd(), filename_too_long, 'txt') assert len(parsed_path) <= 256
def test_parse_out_path_filename_extension_shortening(self): # 252 characters long, but with the .pdf extension it becomes 256 characters long - one too many. filename = '012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901' parsed_filename = ScraperUtils.parse_out_path('', filename, 'pdf') assert parsed_filename == '{}.{}'.format(filename[:-1], 'pdf')
def test_filename_invalid(self): filename = None parsed_path = ScraperUtils.parse_out_path(r'C:\\Example\\Path', filename, 'pdf') assert parsed_path == os.path.join(r'C:\\Example\\Path', '.pdf')
def test_parse_out_path_illegal_characters(self): filename_invalid_chars = 't<>:e"/s\\t|?n*ame' assert ScraperUtils.parse_out_path('', filename_invalid_chars, 'pdf') == os.path.join( '', 'testname.pdf')