"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/common.py" between
recode-3.7.4.tar.gz and recode-3.7.5.tar.gz

About: recode is a charset converter tool and library (fork of the original and now unmaintained GNU recode).

common.py  (recode-3.7.4):common.py  (recode-3.7.5)
skipping to change at line 27 skipping to change at line 27
return self[attribute] return self[attribute]
def __setattr__(self, attribute, value): def __setattr__(self, attribute, value):
self[attribute] = value self[attribute] = value
run = Run() run = Run()
def external(flag): def external(flag):
run.external = flag run.external = flag
def request(text): def request(text, encoding='utf-8'):
run.request = text run.request = bytes(text, encoding)
# Functions only meant to be imported into real testing modules, where # Functions only meant to be imported into real testing modules, where
# pytest is meant to find and use them. # pytest is meant to find and use them.
def setup_module(module): def setup_module(module):
for variable in ('LANG', 'LANGUAGE', for variable in ('LANG', 'LANGUAGE',
'LC_ALL', 'LC_MESSAGES', 'LC_COLLATE'): 'LC_ALL', 'LC_MESSAGES', 'LC_COLLATE'):
if variable in os.environ: if variable in os.environ:
del os.environ[variable] del os.environ[variable]
os.environ['DEFAULT_CHARSET'] = 'ASCII' os.environ['DEFAULT_CHARSET'] = 'ASCII'
skipping to change at line 69 skipping to change at line 69
if not recode_program: if not recode_program:
py.test.skip() py.test.skip()
command = command.replace('$R', recode_program + ' --ignore=:iconv:') command = command.replace('$R', recode_program + ' --ignore=:iconv:')
try: try:
# FIXME: Find a more portable solution than checking the OS # FIXME: Find a more portable solution than checking the OS
output = subprocess.check_output(command, universal_newlines=True, shell =os.name != 'nt') output = subprocess.check_output(command, universal_newlines=True, shell =os.name != 'nt')
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
output = e.output output = e.output
return output return output
def recode_output(input): def recode_output(input, encoding='utf-8'):
if type(input) != bytes:
input = bytes(input, encoding)
if run.external: if run.external:
file(run.work, 'wb').write(input) open(run.work, 'wb').write(input)
return external_output('$R %s < %s' % (run.request, run.work)) return external_output('$R %s < %s' % (run.request, run.work))
if outer is None: if outer is None:
py.test.skip() py.test.skip()
return outer.recode(run.request, input) return outer.recode(run.request, input)
def recode_iconv_output(input): def recode_iconv_output(input, encoding='utf-8'):
if type(input) != bytes:
input = bytes(input, encoding)
if run.external or outer_iconv is None: if run.external or outer_iconv is None:
py.test.skip() py.test.skip()
return outer_iconv.recode(run.request, input) return outer_iconv.recode(run.request, input)
def recode_back_output(input): def recode_back_output(input, encoding='utf-8'):
before, after = run.request.split('..') if type(input) != bytes:
input = bytes(input, encoding)
before, after = run.request.split(b'..')
if run.external: if run.external:
file(run.work, 'wb').write(input) open(run.work, 'wb').write(input)
external_output('$R %s %s' % (run.request, run.work)) external_output(b'$R %s %s' % (run.request, run.work))
return external_output('$R %s..%s < %s' % (after, before, run.work)) return external_output(b'$R %s..%s < %s' % (after, before, run.work))
if outer is None: if outer is None:
py.test.skip() py.test.skip()
temp = outer.recode(run.request, input) temp = outer.recode(run.request, input)
return outer.recode('%s..%s' % (after, before), temp) return outer.recode(b'%s..%s' % (after, before), temp)
def validate(input, expected): def validate(input, expected, encoding='utf-8'):
output = recode_output(input) output = recode_output(input)
if type(input) != bytes:
output = output.decode(encoding)
import sys
print(type(input), type(output), type(expected))
assert_or_diff(output, expected) assert_or_diff(output, expected)
def validate_back(input): def validate_back(input, encoding='utf-8'):
output = recode_back_output(input) output = recode_back_output(input)
if type(input) != bytes:
output = output.decode(encoding)
assert_or_diff(output, input) assert_or_diff(output, input)
 End of changes. 11 change blocks. 
13 lines changed or deleted 25 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)