def test_invalid_version(self): with pytest.raises(ProjectException) as exc_info: Project({'NAME': 'test'}, 'test', None, None, None, None, None, None) assert exc_info.value.args[0] == "Invalid version: None" with pytest.raises(ProjectException) as exc_info: Project({'NAME': 'test'}, 'test', 'dev', None, None, None, None, None) assert exc_info.value.args[0] == "Invalid version: dev"
def test_run(self, mock_import_module, mock_command_run): # Used to mock module load mock_import_module.return_value = {} project_path = os.path.join(os.environ['HOME'], 'test') proj = Project({'NAME': 'test'}, 'test', '0.1.0-dev', None, ['main'], ['--custom'], project_path, os.path.join(project_path, 'build')) proj.run('echo foo') mock_command_run.assert_called_with('echo foo', proj.logger)
def test_chdir_same_dir(self, mock_import_module, mock_getcwd, mock_chdir): # Used to mock module load mock_import_module.return_value = {} project_path = os.path.join(os.environ['HOME'], 'test') proj = Project({'NAME': 'test'}, 'test', '0.1.0-dev', None, ['main'], ['--custom'], project_path, os.path.join(project_path, 'build')) mock_getcwd.side_effect = ['foo'] with proj.chdir('foo'): pass mock_chdir.assert_not_called()
def test_set_dist_dir(self, mock_import_module): # Used to mock module load mock_import_module.return_value = {} project_path = os.path.join(os.environ['HOME'], 'test') proj = Project({'NAME': 'test'}, 'test', '0.1.0-dev', None, ['main'], ['--custom'], project_path, os.path.join(project_path, 'build')) proj.dist_dir = 'dist' assert proj.dist_dir == os.path.join(proj.build_dir, 'dist') proj.dist_dir = os.path.join(os.path.dirname(project_path), 'dist') assert proj.dist_dir == os.path.join(os.path.dirname(project_path), 'dist')
def test_step(self, mock_import_module, mock_timer, MockLogger, MockTimeReport): # Used to mock module load mock_import_module.return_value = {} project_path = os.path.join(os.environ['HOME'], 'test') proj = Project({'NAME': 'test'}, 'test', '0.1.0-dev', None, ['main'], ['--custom'], project_path, os.path.join(project_path, 'build')) mock_timer.side_effect = [2, 4] with proj.step('name', 'description'): pass proj.logger.info.assert_called_with('=== %s', 'description') proj.time_report.add.assert_called_with('name', 2)
def test_valid_project(self, mock_import_module): # Used to mock module load mock_import_module.return_value = {} project_path = os.path.join(os.environ['HOME'], 'test') proj = Project({'NAME': 'test'}, 'test', '0.1.0-dev', 'Copyright (c) 2018 Olivier Sechet', ['main'], [{'--custom'}], project_path, os.path.join(project_path, 'build')) assert proj.logger assert proj.name == 'test' assert proj.version == semantic_version.Version('0.1.0-dev') assert proj.legal == 'Copyright (c) 2018 Olivier Sechet' assert proj.modules == ['main'] assert proj.custom_args == [{'--custom'}] assert proj.root_dir == project_path assert proj.build_dir == os.path.join(project_path, 'build') assert proj.install_dir == os.path.join(project_path, 'build', 'release') assert proj.dist_dir == os.path.join(project_path, 'build', 'dist') assert proj.report_dir == os.path.join(project_path, 'build', 'report') assert proj.time_report
def test_invalid_build_dir(self): with pytest.raises(ProjectException) as exc_info: Project({'NAME': 'test'}, 'test', '0.1.0-dev', None, ['main'], None, 'test', None) assert exc_info.value.args[0] == "Invalid build directory"
def test_no_modules(self): with pytest.raises(ProjectException) as exc_info: Project({'NAME': 'test'}, 'test', '0.1.0-dev', None, [], None, None, None) assert exc_info.value.args[0] == "At least one module must be defined"
def test_invalid_modules(self): with pytest.raises(ProjectException) as exc_info: Project({'NAME': 'test'}, 'test', '0.1.0-dev', None, None, None, None, None) assert exc_info.value.args[0] == "Modules must be defined as a list"
def test_invalid_name(self): with pytest.raises(ProjectException) as exc_info: Project({'NAME': 'test'}, None, None, None, None, None, None, None) assert exc_info.value.args[0] == "Invalid project name"
def test_invalid_projectfile(self): with pytest.raises(ProjectException) as exc_info: Project(None, None, None, None, None, None, None, None) assert exc_info.value.args[0] == "Invalid projectfile"