def test_no_source(self, tmpdir): project_dir = Path(str(tmpdir)) project = Project.from_dir(project_dir, name='test', version='1.2.3') with Options(project=project): java_config = JavaConfiguration() task_config = PackageConfiguration() task_config.sources = False task_config.doc = False jar_file = java_config.library_dist_dir( ensure=True) / project.name / 'test-1.2.3.jar' _ = java_config.classes_dir(ensure=True) _ = java_config.resources_dir(ensure=True) expected = [ 'jar', '--create', '--file', str(jar_file), '--manifest', Regex('.*'), '-C', Regex('.*/jar_content'), '.' ] with FakeProcessContext(FakeProcess(expected)): with Options(project=project): with patch('builder.java.package.sign_path') as mock_signer: mock_signer.return_value = {} java_package(java_config, task_config, []) mock_signer.assert_called_once_with(jar_file)
def test_sources_no_dir(self, tmpdir): project_dir = Path(str(tmpdir)) project = Project.from_dir(project_dir, name='test', version='1.2.3') with Options(project=project): config = JavaConfiguration() task_config = PackageConfiguration() task_config.doc = False jar_file = config.library_dist_dir( ensure=True) / project.name / 'test-1.2.3.jar' _ = config.classes_dir(ensure=True) _ = config.resources_dir(ensure=True) code_dir = config.code_dir() expected = [ 'jar', '--create', '--file', str(jar_file), '--manifest', Regex('.*'), '-C', Regex('.*/jar_content'), '.' ] with FakeProcessContext(FakeProcess(expected)): with pytest.raises(ValueError) as info: with Options(project=project): with patch( 'builder.java.package.sign_path') as mock_signer: mock_signer.return_value = {} java_package(config, task_config, []) mock_signer.assert_called_once_with(jar_file) assert info.value.args[ 0] == f'Cannot build a sources archive since {code_dir} does not exist.'
def test_good_javac(self): java_directory = Path('src') classes_directory = Path('classes') expected = ['javac', '-d', str(classes_directory), Regex(r'@.*')] with FakeProcessContext(FakeProcess(expected)): run_compiler(java_directory, classes_directory, [])
def test_create_manifest(self): lines = _create_manifest('1.2.3', 'my desc') assert lines == [ 'Manifest-Version: 1.0', Regex( r'Created-By: \d+(?:\.\d+(?:\.\d+)?)? [(]Builder, v\d+\.\d+\.\d+[)]' ), 'Specification-Title: my desc', 'Specification-Version: 1.2.3', 'Implementation-Title: my desc', 'Implementation-Version: 1.2.3' ]
def test_javac_compile_error(self): java_directory = Path('src') classes_directory = Path('classes') expected = ['javac', '-d', str(classes_directory), Regex(r'@.*')] with FakeProcessContext(FakeProcess(expected, rc=1)): with pytest.raises(ValueError) as info: run_compiler(java_directory, classes_directory, []) assert info.value.args[0] == 'Java source could not be compiled.'
def test_sources_with_dir(self, tmpdir): project_dir = Path(str(tmpdir)) project = Project.from_dir(project_dir, name='test', version='1.2.3') with Options(project=project): config = JavaConfiguration() task_config = PackageConfiguration() task_config.doc = False jar_file = config.library_dist_dir( ensure=True) / project.name / 'test-1.2.3.jar' sources_jar_file = config.library_dist_dir( ) / project.name / 'test-1.2.3-sources.jar' _ = config.classes_dir(ensure=True) resources_dir = config.resources_dir(ensure=True) code_dir = config.code_dir(ensure=True) expected_jar = [ 'jar', '--create', '--file', str(jar_file), '--manifest', Regex('.*'), '-C', Regex('.*/jar_content'), '.' ] expected_sources = [ 'jar', '--create', '--file', str(sources_jar_file), '-C', str(code_dir), '.', '-C', str(resources_dir), '.' ] with FakeProcessContext( [FakeProcess(expected_jar), FakeProcess(expected_sources)]): with Options(project=project): with patch('builder.java.package.sign_path') as mock_signer: mock_signer.return_value = {} java_package(config, task_config, []) assert mock_signer.mock_calls == [ call(jar_file), call(sources_jar_file) ]
def test_simple_java_compile(self, tmpdir): project_dir = Path(str(tmpdir)) project = Project.from_dir(project_dir) with Options(project=project): config = JavaConfiguration() # This needs to exist for the test to work. _ = config.code_dir(ensure=True) expected = ['javac', '-d', str(config.classes_dir()), Regex(r'@.*')] with FakeProcessContext(FakeProcess(expected)): java_compile(config, [])
def test_jar_no_resources(self): jar_file = Path('file.jar') directory = Path('classes') expected = [ 'jar', '--create', '--file', str(jar_file), '--manifest', Regex('.*'), '-C', str(directory), '.' ] manifest = _create_manifest('1.2.3', 'my desc') with FakeProcessContext(FakeProcess(expected)): with patch('builder.java.package.sign_path') as mock_signer: mock_signer.return_value = {} result = _run_packager(manifest, None, jar_file, directory, None) mock_signer.assert_called_once_with(jar_file) assert result == {}