def test_builder_init(): b = builder.PiWheelsBuilder('foo', '0.1') assert b.wheel_dir is None assert b.package == 'foo' assert b.version == '0.1' assert b.duration is None assert b.output == '' assert b.files == [] assert not b.status
def test_builder_build_clean(mock_systemd, tmpdir): with mock.patch('tempfile.TemporaryDirectory') as tmpdir_mock, \ mock.patch('piwheels.slave.builder.Popen') as popen_mock: tmpdir_mock().name = str(tmpdir) popen_mock().wait.side_effect = lambda timeout: None popen_mock().returncode = 0 b = builder.PiWheelsBuilder('foo', '0.1') b.build() assert b.status b.clean() assert tmpdir_mock().cleanup.call_args == mock.call()
def test_builder_build_success(mock_archive, mock_systemd, tmpdir): with mock.patch('tempfile.TemporaryDirectory') as tmpdir_mock, \ mock.patch('piwheels.slave.builder.Popen') as popen_mock: tmpdir_mock().name = str(tmpdir) def wait(timeout): with tmpdir.join('foo-0.1-cp34-cp34m-linux_armv7l.whl').open('wb') as f: f.write(mock_archive) popen_mock().wait.side_effect = wait popen_mock().returncode = 0 b = builder.PiWheelsBuilder('foo', '0.1') b.build() assert b.status args, kwargs = popen_mock.call_args assert args[0][-1] == 'foo==0.1' assert len(b.files) == 1 assert b.files[0].filename == 'foo-0.1-cp34-cp34m-linux_armv7l.whl'
def test_builder_build_timeout(mock_systemd, tmpdir): with mock.patch('tempfile.TemporaryDirectory') as tmpdir_mock, \ mock.patch('piwheels.slave.builder.Popen') as popen_mock, \ mock.patch('piwheels.slave.builder.time') as time_mock: tmpdir_mock().name = str(tmpdir) popen_mock().wait.side_effect = TimeoutExpired('pip3', 300) popen_mock().returncode = -9 time_mock.side_effect = [0, 100, 1000, 1001] b = builder.PiWheelsBuilder('foo', '0.1') b.build() assert not b.status args, kwargs = popen_mock.call_args assert args[0][-1] == 'foo==0.1' assert len(b.files) == 0 assert popen_mock().terminate.call_count == 1 assert popen_mock().kill.call_count == 1
def test_builder_as_message(): b = builder.PiWheelsBuilder('foo', '0.1') assert b.as_message() == ['foo', '0.1', False, None, '', []]