32
34
cmd.finalize_options()
33
35
self.assertEqual(cmd.optimize, 2)
35
@unittest.skipUnless(not sys.dont_write_bytecode,
36
'byte-compile not supported')
37
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
37
38
def test_byte_compile(self):
38
pkg_dir, dist = self.create_dist()
39
project_dir, dist = self.create_dist()
39
41
cmd = install_lib(dist)
40
42
cmd.compile = cmd.optimize = 1
42
f = os.path.join(pkg_dir, 'foo.py')
44
f = os.path.join(project_dir, 'foo.py')
43
45
self.write_file(f, '# python file')
44
46
cmd.byte_compile([f])
45
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
46
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
47
pyc_file = imp.cache_from_source('foo.py', debug_override=True)
48
pyo_file = imp.cache_from_source('foo.py', debug_override=False)
49
self.assertTrue(os.path.exists(pyc_file))
50
self.assertTrue(os.path.exists(pyo_file))
48
52
def test_get_outputs(self):
49
pkg_dir, dist = self.create_dist()
53
project_dir, dist = self.create_dist()
50
56
cmd = install_lib(dist)
52
58
# setting up a dist environment
53
59
cmd.compile = cmd.optimize = 1
54
cmd.install_dir = pkg_dir
55
f = os.path.join(pkg_dir, 'foo.py')
56
self.write_file(f, '# python file')
57
cmd.distribution.py_modules = [pkg_dir]
60
cmd.install_dir = self.mkdtemp()
61
f = os.path.join(project_dir, 'spam', '__init__.py')
62
self.write_file(f, '# python package')
58
63
cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
59
cmd.distribution.packages = [pkg_dir]
64
cmd.distribution.packages = ['spam']
60
65
cmd.distribution.script_name = 'setup.py'
62
# get_output should return 4 elements
63
self.assertTrue(len(cmd.get_outputs()) >= 2)
67
# get_outputs should return 4 elements: spam/__init__.py, .pyc and
68
# .pyo, foo.import-tag-abiflags.so / foo.pyd
69
outputs = cmd.get_outputs()
70
self.assertEqual(len(outputs), 4, outputs)
65
72
def test_get_inputs(self):
66
pkg_dir, dist = self.create_dist()
73
project_dir, dist = self.create_dist()
67
76
cmd = install_lib(dist)
69
78
# setting up a dist environment
70
79
cmd.compile = cmd.optimize = 1
71
cmd.install_dir = pkg_dir
72
f = os.path.join(pkg_dir, 'foo.py')
73
self.write_file(f, '# python file')
74
cmd.distribution.py_modules = [pkg_dir]
80
cmd.install_dir = self.mkdtemp()
81
f = os.path.join(project_dir, 'spam', '__init__.py')
82
self.write_file(f, '# python package')
75
83
cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
76
cmd.distribution.packages = [pkg_dir]
84
cmd.distribution.packages = ['spam']
77
85
cmd.distribution.script_name = 'setup.py'
79
# get_input should return 2 elements
80
self.assertEqual(len(cmd.get_inputs()), 2)
87
# get_inputs should return 2 elements: spam/__init__.py and
88
# foo.import-tag-abiflags.so / foo.pyd
89
inputs = cmd.get_inputs()
90
self.assertEqual(len(inputs), 2, inputs)
82
92
def test_dont_write_bytecode(self):
83
93
# makes sure byte_compile is not used
84
pkg_dir, dist = self.create_dist()
94
dist = self.create_dist()[1]
85
95
cmd = install_lib(dist)