File: test_pathlib2_with_py2_unicode_literals.py

package info (click to toggle)
python-pathlib2 2.2.0%2Breally2.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 248 kB
  • ctags: 400
  • sloc: python: 2,924; makefile: 3
file content (26 lines) | stat: -rw-r--r-- 745 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

import __future__
import os
import sys
import types


def compile_source_file(source_file, flags):
    with open(source_file, "r") as f:
        source = f.read()
    return compile(source, os.path.basename(source_file), 'exec', flags)


if __name__ == "__main__":
    # Compile and run test_pathlib.py as if
    # "from __future__ import unicode_literals" had been added at the top.
    flags = __future__.CO_FUTURE_UNICODE_LITERALS
    code = compile_source_file("test_pathlib2.py", flags)
    mod = types.ModuleType('test_pathlib2')
    mod.__file__ = "test_pathlib2.py"
    sys.modules[mod.__name__] = mod
    # hack six.u() not to try to decode the string
    import six
    six.u = lambda s: s
    eval(code, mod.__dict__)
    mod.main()