#reindent.py test import subprocess def test_strings(src='', target='', s=True): args = ('python', 'reindent.py') if s: args += ('-s', ) p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) p.stdin.write(src.encode('utf-8')) w = p.communicate()[0].decode('utf-8') if w != target: print('Failed test' + '-s' if s else '') print('Expected: %r' % target) print('Got: %r' % w) # Tab should not be replaced test_strings(src="'\t'", target="'\t'\n", s=True) # Tab should be replaced test_strings(src="'\t'", target="' '\n", s=False) # Tab in string is left alone. Last tab is replaced. test_strings( src=""" '''\t '''\t""", target=""" '''\t '''\n""", s=True) # Tab in string is removed due to _rstrip. Last tab is replaced. test_strings( src=""" '''\t '''\t""", target=""" ''' '''\n""", s=False)