Commit | Line | Data |
---|---|---|
0f9675ba FC |
1 | from pathlib import Path |
2 | import sys | |
3 | if '' in sys.path: sys.path.remove('') | |
4 | sys.path.append(str(Path(__file__).parent.parent.parent)) | |
0f9675ba | 5 | from unittest import TestCase |
b1af73f2 | 6 | from unittest.mock import patch |
0f9675ba | 7 | from setuptools.dist import Distribution |
b1af73f2 FC |
8 | from setuptools.command.develop import develop |
9 | from setup import BaseCommand, SetupDevelopmentCommand, ModelsCommand, \ | |
10 | ImagesCommand, L10nCommand, BDistAppsCommand | |
53ddf3c3 | 11 | from ya2.build.build import exec_cmd |
807c4e10 | 12 | import os |
b1af73f2 | 13 | import direct.dist.commands, setup |
0f9675ba FC |
14 | |
15 | class SetupTests(TestCase): | |
16 | ||
807c4e10 FC |
17 | # def setUp(self): |
18 | # self._prev_argv = sys.argv | |
0f9675ba | 19 | |
807c4e10 FC |
20 | # def tearDown(self): |
21 | # sys.argv = self._prev_argv | |
0f9675ba | 22 | |
b1af73f2 | 23 | @patch.object(develop, 'run') |
807c4e10 | 24 | @patch('setup.Popen', autospec=True) |
b1af73f2 FC |
25 | def test_setup_development_command(self, popen, dev_run): |
26 | s = SetupDevelopmentCommand(Distribution()) | |
27 | s.run() | |
28 | dev_run.assert_called_once() | |
29 | for i, arg_list in enumerate(popen.call_args_list): | |
30 | arg_list = arg_list.args[0] | |
31 | assert 'python' in arg_list[0] | |
32 | assert 'setup.py' in arg_list[1] | |
33 | a = ['lang', 'models', 'images'] | |
34 | assert a[i] == arg_list[2] | |
35 | assert popen.return_value.communicate.call_count == 3 | |
36 | ||
0f9675ba | 37 | def test_cores(self): |
d3ef798c | 38 | cmd = BaseCommand(Distribution()) |
addec9c9 FC |
39 | ncores = int(exec_cmd('grep -c ^processor /proc/cpuinfo')) |
40 | self.assertEqual(cmd.cores, ncores) | |
807c4e10 | 41 | with patch.object(setup, 'argv', ['python setup.py', '--cores=2']): |
b1af73f2 FC |
42 | cmd = BaseCommand(Distribution()) |
43 | self.assertEqual(cmd.cores, 2) | |
44 | ||
807c4e10 | 45 | @patch('setup.ModelsBuilder', autospec=True) |
b1af73f2 FC |
46 | def test_models_command(self, mb_mock): |
47 | cmd = ModelsCommand(Distribution()) | |
48 | cmd.run() | |
49 | assert mb_mock.call_count == 1 | |
b1af73f2 | 50 | ncores = int(exec_cmd('grep -c ^processor /proc/cpuinfo')) |
524e2ef5 FC |
51 | assert mb_mock.call_args_list[0].args == ('assets/models', ncores) |
52 | mb_mock.return_value.build.assert_called_once() | |
b1af73f2 FC |
53 | build_mock = mb_mock.return_value.build |
54 | build_mock.assert_called_once() | |
524e2ef5 | 55 | assert not build_mock.call_args_list[0].args |
b1af73f2 | 56 | |
807c4e10 | 57 | @patch('setup.ImagesBuilder', autospec=True) |
524e2ef5 | 58 | @patch('setup.ScreenshotsBuilder', autospec=True) |
b1af73f2 FC |
59 | def test_images_command(self, screenshot_mock, images_mock): |
60 | cmd = ImagesCommand(Distribution()) | |
61 | cmd.run() | |
62 | screenshot_mock.assert_called_once() | |
63 | assert len(screenshot_mock.call_args_list[0].args) | |
64 | assert all(isinstance(a, str) for a in screenshot_mock.call_args_list[0].args[0]) | |
524e2ef5 FC |
65 | build_mock = images_mock.return_value.build |
66 | build_mock.assert_called_once() | |
67 | assert not build_mock.call_args_list[0].args | |
807c4e10 | 68 | assert images_mock.call_count == 1 |
b1af73f2 | 69 | assert all('assets/images' in a for a in images_mock.call_args_list[0].args[0]) |
807c4e10 FC |
70 | ncores = int(exec_cmd('grep -c ^processor /proc/cpuinfo')) |
71 | assert images_mock.call_args_list[0].args[1] == ncores | |
72 | images_mock.return_value.build.assert_called_once() | |
73 | build_mock = images_mock.return_value.build | |
74 | build_mock.assert_called_once() | |
75 | assert not build_mock.call_args_list[0].args | |
b1af73f2 | 76 | |
807c4e10 | 77 | @patch('setup.LanguageBuilder', autospec=True) |
b1af73f2 FC |
78 | def test_l10n_command(self, l_mock): |
79 | cmd = L10nCommand(Distribution()) | |
80 | cmd.run() | |
2c6a6ed1 | 81 | assert l_mock.call_count == 1 |
b1af73f2 FC |
82 | build_args = l_mock.call_args_list[0].args |
83 | assert isinstance(build_args[0], str) | |
84 | assert 'locale' in build_args[1] | |
85 | assert isinstance(build_args[2], str) | |
86 | assert 'locale' in build_args[3] | |
87 | build_mock = l_mock.return_value.build | |
59537c34 | 88 | build_mock.call_count == 2 # build_mock.assert_called_once() |
b1af73f2 FC |
89 | assert not build_mock.call_args_list[0].args |
90 | ||
91 | @patch.object(direct.dist.commands.bdist_apps, 'run', autospec=True) | |
92 | @patch.object(os, 'system', autospec=True) | |
807c4e10 | 93 | @patch('setup.AppImageBuilder', autospec=True) |
b1af73f2 FC |
94 | def test_bdistapps_command(self, a_mock, o_mock, b_mock): |
95 | cmd = BDistAppsCommand(Distribution()) | |
96 | cmd.run() | |
97 | assert o_mock.call_count == 1 | |
98 | assert 'patch' in o_mock.call_args_list[0].args[0] | |
99 | assert a_mock.call_count == 1 | |
100 | assert len(a_mock.call_args_list[0].args) == 1 | |
101 | build_mock = a_mock.return_value.build | |
102 | build_mock.assert_called_once() | |
103 | build_args = build_mock.call_args_list[0].args | |
104 | assert isinstance(build_args[0], str) | |
105 | assert isinstance(build_args[1], str) | |
106 | assert 'https' in build_args[2] | |
807c4e10 | 107 | with patch.object(setup, 'argv', ['python setup.py', '--no-linux=1']): |
b1af73f2 FC |
108 | cmd = BDistAppsCommand(Distribution()) |
109 | cmd.run() | |
110 | assert a_mock.call_count == 1 | |
111 | ||
112 | def test_setup(self): | |
113 | d = setup._build_setup_arguments() | |
114 | assert isinstance(d['name'], str) | |
115 | assert isinstance(d['version'], str) | |
116 | assert 'win_amd64' in d['options']['build_apps']['platforms'] | |
117 | assert 'manylinux2010_x86_64' in d['options']['build_apps']['platforms'] | |
118 | assert len(d['options']['build_apps']['platforms']) == 2 | |
119 | assert 'win_amd64' in d['options']['bdist_apps']['installers'] | |
120 | assert 'manylinux2010_x86_64' in d['options']['bdist_apps']['installers'] | |
121 | assert len(d['options']['bdist_apps']['installers']) == 2 | |
807c4e10 | 122 | with patch.object(setup, 'argv', ['python setup.py', '--no-linux']): |
b1af73f2 FC |
123 | d = setup._build_setup_arguments() |
124 | assert 'win_amd64' in d['options']['build_apps']['platforms'] | |
125 | assert 'manylinux2010_x86_64' not in d['options']['build_apps']['platforms'] | |
126 | assert len(d['options']['build_apps']['platforms']) == 1 | |
127 | assert 'win_amd64' in d['options']['bdist_apps']['installers'] | |
128 | assert 'manylinux2010_x86_64' not in d['options']['bdist_apps']['installers'] | |
129 | assert len(d['options']['bdist_apps']['installers']) == 1 | |
807c4e10 | 130 | with patch.object(setup, 'argv', ['python setup.py', '--no-windows']): |
b1af73f2 FC |
131 | d = setup._build_setup_arguments() |
132 | assert 'win_amd64' not in d['options']['build_apps']['platforms'] | |
133 | assert 'manylinux2010_x86_64' in d['options']['build_apps']['platforms'] | |
134 | assert len(d['options']['build_apps']['platforms']) == 1 | |
135 | assert 'win_amd64' not in d['options']['bdist_apps']['installers'] | |
136 | assert 'manylinux2010_x86_64' in d['options']['bdist_apps']['installers'] | |
137 | assert len(d['options']['bdist_apps']['installers']) == 1 |