def test_generate_package(self, m_zipfile, m_join): """ Ensures that a package file is created with correct name and location """ # First, create a workspace to give to Packager workspace = Workspace("ws/root", ws_name="ws_test", log_level='debug') # Create project project = Project(workspace, 'prj/path') # Instantiate a Packager instance packager = Packager(workspace=workspace, project=project, generate_pd=False, dst_path="dst/path") packager._package_descriptor = True # Prepare mocks context_manager_mock = Mock() m_zipfile.ZipFile.return_value = context_manager_mock enter_mock = Mock() exit_mock = Mock() setattr(context_manager_mock, '__enter__', enter_mock) setattr(context_manager_mock, '__exit__', exit_mock) # execute packager.generate_package("package_name") # make assertions self.assertEqual(m_join.call_args_list[-1], mock.call('dst/path', 'package_name.son'))
def test_validate_project_invalid(self): """ Tests the validation of an invalid SONATA project. """ prj_path = os.path.join(SAMPLES_DIR, 'sample_project_invalid') project = Project(self._workspace, prj_path) validator = Validator(workspace=self._workspace) validator.validate_project(project) self.assertGreater(validator.error_count, 0)
def test_validate_project_warning(self): """ Tests the validation of a SONATA project with warnings. """ prj_path = os.path.join(SAMPLES_DIR, 'sample_project_warning') project = Project(self._workspace, prj_path) validator = Validator(workspace=self._workspace) validator.validate_project(project) self.assertEqual(validator.error_count, 0) self.assertGreater(validator.warning_count, 0)
def test_validate_project_valid(self): """ Tests the validation of a valid SONATA project. """ self.reset_counters() prj_path = os.path.join(SAMPLES_DIR, 'sample_project_valid') project = Project(self._workspace, prj_path) validator = Validator(workspace=self._workspace) validator.validate_project(project) self.assertEqual(val.log.error.counter, 0) self.assertEqual(val.log.warning.counter, 0)
def test_package_gds(self): """ Test the validation of the project general description section """ # First, create a workspace to give to Packager workspace = Workspace("ws/root", ws_name="ws_test", log_level='debug') # Create project project = Project(workspace, 'prj/path') # Instantiate a Packager instance packager = Packager(workspace=workspace, project=project, generate_pd=False, dst_path="dst/path") packager._package_descriptor = True # Create fake project configuration prj_config = { 'version': '0.5', 'package': { 'version': '0.1', 'name': 'sonata-project-sample', 'vendor': 'com.sonata.project', 'maintainer': 'Name, Company, Contact', 'description': 'Project description', }, 'descriptor_extension': 'yml' } # Remove package keys, one by one... for key in prj_config['package']: value = prj_config['package'].pop(key) self.assertIsNone(packager.package_gds(prj_config)) prj_config['package'][key] = value # Make prj_config complete... prj_config['name'] = 'sonata - project - sample' self.assertTrue(packager.package_gds(prj_config))
def __init__(self, *args, **kwargs): super(IntPDTester, self).__init__(*args, **kwargs) ws = Workspace("") prj = Project(ws, '/') self.pck = Packager(workspace=ws, project=prj, generate_pd=False)