Пример #1
0
    def test_packager_copies_all_to_output_directory_then_zips(self, filesystem):
        packager = TemplatePackager()
        project = ProjectDescriptor('cest')
        project.targets['default'] = TargetDescription('default')
        project.build.packages.append(PackageDescription('api'))
        project.test.packages.append(PackageDescription('test'))
        project.targets['default'].build.packages.append(PackageDescription('domain'))
        project.targets['default'].dockerfile = 'Dockerfile'
        filesystem.directory_exists.return_value = False
        filesystem.path_to.return_value = ''

        packager.pack(project, 'dist')

        filesystem.create_directory.assert_called_once_with('dist')
        filesystem.copy_file.assert_has_calls([
            mock.call('project.yaml', 'dist/project.yaml'),
            mock.call('main.cpp', 'dist/'),
            mock.call('Dockerfile', 'dist/')
        ])
        filesystem.copy_directory.assert_has_calls([
            mock.call('api', 'dist/api'),
            mock.call('domain', 'dist/domain'),
            mock.call('test', 'dist/test')
        ])
        filesystem.zip.assert_called_once_with('dist', 'cest')
        filesystem.remove_directory.assert_called_once_with('dist')
Пример #2
0
    def test_packaging_bit_raises_exception_when_output_directory_exists(self, filesystem):
        filesystem.directory_exists.return_value = True
        packager = BitPackager()
        project = ProjectDescriptor('cest')
        project.build.packages.append(PackageDescription('fakeit'))

        self.assertRaises(PackagingFailure, packager.pack, project, 'dist')
Пример #3
0
 def test_compose_from_description_with_customized_bit_compilation(self, filesystem):
     yaml_load = {
         'name': 'HalfLife3',
         'build': {
             'bits': {
                 'arduino': {
                     'version': '1.0.0',
                     'target': 'nano33',
                     'cflags': ['-DBIT_FLAG']
                 }
             }
         }
     }
     filesystem.find.side_effect = [['tests/test_one.cpp'], ['nano33/nano33.cpp'], []]
     filesystem.parent_directory.return_value = '.'
     project_description = project_descriptor_parser.parse_yaml(yaml_load)
     arduino_bit = ProjectDescriptor(
         name='arduino',
         targets={
             'nano33': TargetDescription(
                 name='nano33',
                 build=CompilationPlan(
                     cflags=['-mcpu=atmel'],
                     packages=[PackageDescription(path='nano33')]
                 )
             )
         },
         declared_bit=project_description.build.declared_bits[0]
     )
     project_description.build.bits['arduino'] = arduino_bit
     project = project_composer.compose(project_description, 'default')
     assert project.target.bits[0].packages[0].path == 'bits/arduino/nano33'
     assert project.target.bits[0].packages[0].cflags == ['-mcpu=atmel', '-DBIT_FLAG']
Пример #4
0
    def test_packaging_creates_output_directory(self, filesystem):
        filesystem.directory_exists.return_value = False
        packager = BitPackager()
        project = ProjectDescriptor('cest')
        project.targets['default'] = TargetDescription('default')
        project.build.packages.append(PackageDescription('api'))
        project.targets['default'].build.packages.append(PackageDescription('domain'))

        packager.pack(project, 'dist')

        filesystem.create_directory.assert_called_once_with('dist')
        filesystem.copy_file.assert_called_once_with('project.yaml', 'dist/project.yaml')
        filesystem.copy_directory.assert_has_calls([
            mock.call('api', 'dist/api'),
            mock.call('domain', 'dist/domain'),
        ])
        filesystem.zip.assert_called_once_with('dist', 'cest')
        filesystem.remove_directory.assert_called_once_with('dist')
Пример #5
0
 def test_project_loader_without_bits(self, project_composer,
                                      project_descriptor_parser):
     # Given
     project_descriptor_parser.parse_from.return_value = ProjectDescriptor()
     loader = project_loader.ProjectLoader()
     # When
     loader.load('.')
     # Then
     project_descriptor_parser.parse_from.assert_called_once_with('.')
     project_composer.compose.assert_called_once_with(
         project_descriptor_parser.parse_from.return_value)
Пример #6
0
    def test_publish_service_fails_when_packing_project_fails(
            self, project_descriptor_parser):
        project_descriptor = ProjectDescriptor('cpm-hub')
        project_descriptor_parser.parse_from.return_value = project_descriptor
        bit_packager = mock.MagicMock()
        bit_packager.pack.side_effect = PackagingFailure
        cpm_hub_connector = mock.MagicMock()
        service = PublishService(cpm_hub_connector, bit_packager=bit_packager)

        self.assertRaises(PackagingFailure, service.publish)

        bit_packager.pack.assert_called_once_with(project_descriptor, 'dist')
Пример #7
0
def parse_yaml(yaml_contents):
    project_description = ProjectDescriptor(yaml_contents['name'])
    project_description.version = yaml_contents.get('version', '')
    project_description.description = yaml_contents.get('description', '')
    project_description.build = parse_compilation_plan(
        get_or_default_to(yaml_contents, 'build', {}))
    project_description.test = parse_compilation_plan(
        get_or_default_to(yaml_contents, 'test', {}))
    project_description.targets = parse_targets(
        get_or_default_to(yaml_contents, 'targets', {}))
    return project_description
Пример #8
0
 def test_project_loader_with_declared_bits(self, project_composer,
                                            project_descriptor_parser):
     # Given
     project_descriptor = ProjectDescriptor()
     project_descriptor.build.declared_bits = [DeclaredBit('bit', '2.2')]
     project_descriptor_parser.parse_from.return_value = project_descriptor
     loader = project_loader.ProjectLoader()
     # When
     loader.load('.')
     # Then
     project_descriptor_parser.parse_from.assert_has_calls(
         [mock.call('.'), mock.call('bits/bit')])
     project_composer.compose.assert_called_once_with(project_descriptor)
Пример #9
0
    def test_publish_service_loads_project_then_packages_it_and_uploads_it(
            self, project_descriptor_parser):
        project_descriptor = ProjectDescriptor('cpm-hub')
        project_descriptor_parser.parse_from.return_value = project_descriptor
        bit_packager = mock.MagicMock()
        bit_packager.pack.return_value = 'packaged_file.zip'
        cpm_hub_connector = mock.MagicMock()
        service = PublishService(cpm_hub_connector, bit_packager=bit_packager)

        service.publish()

        bit_packager.pack.assert_called_once_with(project_descriptor, 'dist')
        cpm_hub_connector.publish_bit.assert_called_once_with(
            project_descriptor, 'packaged_file.zip')
Пример #10
0
    def test_publish_service_fails_when_uploading_bit_fails(
            self, project_descriptor_parser):
        project_descriptor = ProjectDescriptor('cpm-hub')
        project_descriptor_parser.parse_from.return_value = project_descriptor
        bit_packager = mock.MagicMock()
        bit_packager.pack.return_value = 'packaged_file.zip'
        cpm_hub_connector = mock.MagicMock()
        cpm_hub_connector.publish_bit.side_effect = AuthenticationFailure
        service = PublishService(cpm_hub_connector, bit_packager=bit_packager)

        self.assertRaises(AuthenticationFailure, service.publish)

        cpm_hub_connector.publish_bit.assert_called_once_with(
            project_descriptor, 'packaged_file.zip')
Пример #11
0
 def test_loading_project_when_some_bit_is_not_installed(
         self, project_composer, project_descriptor_parser):
     # Given
     project_descriptor = ProjectDescriptor()
     project_descriptor.build.declared_bits = [DeclaredBit('bit', '2.2')]
     project_descriptor_parser.parse_from.side_effect = [
         project_descriptor, ProjectDescriptorNotFound
     ]
     loader = project_loader.ProjectLoader()
     # When
     loader.load('.', 'default')
     # Then
     project_descriptor_parser.parse_from.assert_has_calls(
         [mock.call('.'), mock.call('bits/bit')])
     project_composer.compose.assert_called_once_with(
         project_descriptor, 'default')
Пример #12
0
    def test_packaging_bit_raises_exception_when_no_packages_are_declared(self):
        packager = BitPackager()
        project = ProjectDescriptor('cest')

        self.assertRaises(PackagingFailure, packager.pack, project, 'dist')