Пример #1
0
 def setUp(self):
     self.tempdir = TempDirectory()
     self.tempdir.write('1/Accession1.fastq.gz', b'the text')
     self.tempdir.write('2/Accession1_1.fastq.gz', b'the text')
     self.tempdir.write('2/Accession1_2.fastq.gz',b'the text')
     self.tempdir_path = self.tempdir.path
     print('temp',self.tempdir_path)
     self.under_test1 = Preparation.new_instance(Spreadsheet.new_instance("MyStudy", [
         RawRead(forward_read='Accession1', reverse_read='T', sample_name='SAMPLE1',
                 taxon_id='1280', library_name='LIB1', sample_accession=None),
         RawRead(forward_read='Accession2', reverse_read='T', sample_name='SAMPLE2',
                 taxon_id='1280', library_name='LIB2', sample_accession=None)]), self.tempdir_path, 0, 0)
     self.under_test2 = Preparation.new_instance(Spreadsheet.new_instance("MyStudy", [
         RawRead(forward_read='Accession1', reverse_read='T', sample_name='SAMPLE1',
                 taxon_id='1280', library_name='LIB1', sample_accession=None),
         RawRead(forward_read='Accession2', reverse_read='T', sample_name='SAMPLE2',
                 taxon_id='1280', library_name='LIB2', sample_accession=None)]), self.tempdir_path, 1, 0)
     self.under_test3 = Preparation.new_instance(Spreadsheet.new_instance("MyStudy", [
         RawRead(forward_read='Accession1', reverse_read='T', sample_name='SAMPLE1',
                 taxon_id='1280', library_name='LIB1', sample_accession=None),
         RawRead(forward_read='Accession2', reverse_read='T', sample_name='SAMPLE2',
                 taxon_id='1280', library_name='LIB2', sample_accession=None)]), self.tempdir_path, 2, 0)
Пример #2
0
    def test_merge_results_from_two_sub_steps(self):
        config = {
            'tssc-config': {
                'write-config-as-results': [{
                    'name': 'sub-step-1',
                    'implementer':
                    'tests.helpers.sample_step_implementers.WriteConfigAsResultsStepImplementer',
                    'config': {
                        'config-1': "config-1",
                        'config-overwrite-me': 'config-1',
                        'required-config-key': 'required'
                    }
                }, {
                    'name': 'sub-step-2',
                    'implementer':
                    'tests.helpers.sample_step_implementers.WriteConfigAsResultsStepImplementer',
                    'config': {
                        'config-2': 'config-2',
                        'config-overwrite-me': 'config-2',
                        'required-config-key': 'required'
                    }
                }]
            }
        }
        config_expected_step_results = {
            'tssc-results': {
                'write-config-as-results': {
                    'config-1': "config-1",
                    'config-2': 'config-2',
                    'config-overwrite-me': 'config-2',
                    'required-config-key': 'required'
                }
            }
        }

        with TempDirectory() as test_dir:
            self._run_step_implementer_test(config, 'write-config-as-results',
                                            config_expected_step_results,
                                            test_dir)
    def test_list_result_files(self):
        with TempDirectory() as temp_dir:
            parent_work_dir_path = os.path.join(temp_dir.path, 'working')
            step_config = {
                'organization': 'test-ORG',
                'application-name': 'test-APP',
                'service-name': 'test-SERVICE',
                'version': '42.0-test'
            }
            step_result = StepResult(
                step_name='test-step',
                sub_step_name='test-sub-step',
                sub_step_implementer_name='test-sub-step-implementer')
            step_result.add_artifact(name='test-step-result-str',
                                     value=['hello', 'world', 'foo'])
            workflow_result = WorkflowResult()
            workflow_result.add_step_result(step_result)
            step_implementer = self.create_step_implementer(
                step_config=step_config,
                parent_work_dir_path=parent_work_dir_path,
                workflow_result=workflow_result)

            archive_path = step_implementer._ResultArtifactsArchive__create_archive(
            )

            archive_zip = zipfile.ZipFile(archive_path)

            artifact_file_path = f"{step_config['organization']}-" \
                f"{step_config['application-name']}-{step_config['service-name']}-" \
                f"{step_config['version']}/test-step/test-sub-step/test-step-result-str"
            with archive_zip.open(artifact_file_path, 'r') as artifact_file:
                artifact_file_contents = artifact_file.read().decode('UTF-8')

                self.assertEqual(
                    artifact_file_contents, """[
    "hello",
    "world",
    "foo"
]""")
Пример #4
0
    def test_give_dir_with_single_file_find_all_attributes(self):
        with TempDirectory() as test_dir:
            # setup test
            test_dir.write(
                'test_result1.xml',
                b'<testsuite time="1.42" tests="42" errors="3" skipped="2" failures="1" />'
            )

            # run test
            report_results, warnings = MavenTestReportingMixin._collect_report_results(
                test_report_dirs=[test_dir.path])

            # verify results
            self.assertEqual(
                report_results, {
                    'time': 1.42,
                    'tests': 42,
                    'errors': 3,
                    'skipped': 2,
                    'failures': 1
                })
            self.assertEqual(warnings, [])
Пример #5
0
    def test_package_file_does_not_exist(self, mock_super_validate):
        with TempDirectory() as test_dir:
            parent_work_dir_path = os.path.join(test_dir.path, 'working')

            package_file_path = '/does/not/exist/package.json'
            step_config = {
                'package-file': package_file_path,
                'npm-run-scripts': 'fake-arg'
            }

            step_implementer = self.create_step_implementer(
                step_config=step_config,
                parent_work_dir_path=parent_work_dir_path,
            )

            with self.assertRaisesRegex(
                    AssertionError,
                    rf'Given npm package file \(package-file\) does not exist: {package_file_path}'
            ):
                step_implementer._validate_required_config_or_previous_step_result_artifact_keys(
                )
                mock_super_validate.assert_called_once_with()
    def test__validate_required_config_or_previous_step_result_artifact_keys_valid(
            self):
        with TempDirectory() as temp_dir:
            parent_work_dir_path = os.path.join(temp_dir.path, 'working')

            temp_dir.write(
                'package.json', b'''{
              "name": "my-awesome-package",
              "version": "42.1"
            }''')
            package_file_path = os.path.join(temp_dir.path, 'package.json')

            step_config = {'package-file': package_file_path}

            step_implementer = self.create_step_implementer(
                step_config=step_config,
                step_name='test',
                implementer='Npm',
                parent_work_dir_path=parent_work_dir_path)

            step_implementer._validate_required_config_or_previous_step_result_artifact_keys(
            )
Пример #7
0
    def test_root_dir_is_not_git_repo(self):
        with TempDirectory() as temp_dir:
            work_dir_path = os.path.join(temp_dir.path, 'working')
            step_config = {'repo-root': '/'}

            step_implementer = self.create_step_implementer(
                step_config=step_config,
                step_name='generate-metadata',
                implementer='Git',
                work_dir_path=work_dir_path,
            )

            result = step_implementer._run_step()

            expected_step_result = StepResult(step_name='generate-metadata',
                                              sub_step_name='Git',
                                              sub_step_implementer_name='Git')
            expected_step_result.success = False
            expected_step_result.message = 'Given directory (repo_root) is not a Git repository'

            self.assertEqual(result.get_step_result_dict(),
                             expected_step_result.get_step_result_dict())
Пример #8
0
    def test_new_google_gallery_created(self, input):
        with TempDirectory() as tempdir:
            sys.argv = [
                "gallery_init",
                "https://photos.app.goo.gl/test",
                "-p",
                tempdir.path,
            ]
            gallery_init.main()

            check_gallery_files(tempdir, [], [])
            self.check_gallery_config(
                os.path.join(tempdir.path, "gallery.json"),
                tempdir.path,
                "Test Gallery",
                "Test Description",
                160,
                "photo.jpg",
                "example.com",
                "google",
                "https://photos.app.goo.gl/test",
            )
Пример #9
0
    def test_check_input_correct_type_incorrect(self):
        with TempDirectory() as input_dir:
            input_dir.write("input_file.vcf", b"foo")
            input_file = os.path.join(input_dir.path, "input_file.vcf")
            args_requires_dir = Namespace(subparser_name="awesomeCommand",
                                          input=input_file,
                                          required_input_type="directory")
            self.assertRaisesRegexp(
                utils.UsageError,
                r"The awesomeCommand command requires a directory.*input_file.vcf.*is a file",
                command_validator._check_input_correct_type, None,
                args_requires_dir)

            args_required_file = Namespace(subparser_name="awesomeCommand",
                                           input=input_dir.path,
                                           required_input_type="file")
            self.assertRaisesRegexp(
                utils.UsageError,
                r"The awesomeCommand command requires a file.*" +
                re.escape(input_dir.path) + r".*is a directory.*",
                command_validator._check_input_correct_type, None,
                args_required_file)
Пример #10
0
    def test_configlint_using_runtime(self, configlint_mock):
        with TempDirectory() as temp_dir:
            yml_file = ''
            temp_dir.write('file.yml', yml_file.encode())
            yml_path: str = os.path.join(temp_dir.path, 'file.yml')
            tssc_results = '''tssc-results:
            '''
            temp_dir.write('tssc-results/tssc-results.yml',
                           tssc_results.encode())
            configlint_rules = ''
            temp_dir.write('config-lint.rules', configlint_rules.encode())
            rules = os.path.join(temp_dir.path, 'config-lint.rules')
            config = {
                'tssc-config': {
                    'validate-environment-configuration': {
                        'implementer': 'Configlint',
                        'config': {
                            'rules': rules
                        }
                    }
                }
            }
            runtime_args = {'yml_path': yml_path}
            expected_step_results = {
                'tssc-results': {
                    'validate-environment-configuration': {
                        'result': {
                            'success': True,
                            'message': 'configlint step completed'
                        },
                        'report-artifacts': []
                    }
                }
            }

            with self.assertRaisesRegex(AttributeError, r'.*.'):
                run_step_test_with_result_validation(
                    temp_dir, 'validate-environment-configuration', config,
                    expected_step_results, runtime_args)
    def test_valid_custom_imagespecfile(self, mock_super_validate):
        with TempDirectory() as test_dir:
            # setup
            parent_work_dir_path = os.path.join(test_dir.path, 'working')
            step_config = {
                'context': test_dir.path,
                'organization': 'mock-org',
                'service-name': 'mock-service',
                'application-name': 'mock-app',
                'imagespecfile': 'MockContainerfile.ubi8'
            }
            test_dir.write('MockContainerfile.ubi8',b'''testing''')

            # run test
            step_implementer = self.create_step_implementer(
                step_config=step_config,
                parent_work_dir_path=parent_work_dir_path,
            )
            step_implementer._validate_required_config_or_previous_step_result_artifact_keys()

            # validate
            mock_super_validate.assert_called_once_with()
Пример #12
0
    def setUp(self):
        """
        Set up a directory with some images to generate frames_meta.csv for
        """
        self.tempdir = TempDirectory()
        self.temp_dir = self.tempdir.path
        self.idx_dir = os.path.join(self.temp_dir, 'idx_dir')
        self.sms_dir = os.path.join(self.temp_dir, 'sms_dir')
        self.tempdir.makedir(self.idx_dir)
        self.tempdir.makedir(self.sms_dir)
        # Write images
        self.time_idx = 5
        self.pos_idx = 7
        self.im = 1500 * np.ones((30, 20), dtype=np.uint16)
        self.channel_names = ['phase', 'brightfield', 'some_other_c', '666']

        for i, c in enumerate(self.channel_names):
            for z in range(5, 10):
                im_name = 'im_c00{}_z00{}_t005_p007.png'.format(i, z)
                cv2.imwrite(os.path.join(self.idx_dir, im_name), self.im)
                im_name = 'img_{}_t005_p007_z00{}.tif'.format(c, z)
                cv2.imwrite(os.path.join(self.sms_dir, im_name), self.im)
Пример #13
0
def test_mvn_quickstart_single_jar():
    with TempDirectory() as temp_dir:
        temp_dir.write('src/main/java/com/mycompany/app/App.java',b'''package com.mycompany.app;
public class App {
    public static void main( String[] args ) {
        System.out.println( "Hello World!" );
    }
}''')
        temp_dir.write('pom.xml',b'''<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany.app</groupId>
    <artifactId>my-app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>''')
        pom_file_path = os.path.join(temp_dir.path, 'pom.xml')
        config = {
            'tssc-config': {
                'package': {
                    'implementer': 'Maven',
                    'config': {
                        'pom-file': str(pom_file_path)
                    }
                }
            }
        }
        expected_step_results = {
            'tssc-results': {
                'package': {
                    'artifacts': {
                        'my-app-1.0-SNAPSHOT.jar': os.path.join(temp_dir.path, 'target', 'my-app-1.0-SNAPSHOT.jar')
                    }
                }
            }
        }
        run_step_test_with_result_validation(temp_dir, 'package', config, expected_step_results)
Пример #14
0
def test_pom_file_missing_version ():
    with TempDirectory() as temp_dir:
        temp_dir.write('pom.xml',b'''<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany.app</groupId>
    <artifactId>my-app</artifactId>
</project>''')
        pom_file_path = os.path.join(temp_dir.path, 'pom.xml')

        config = {
            'tssc-config': {
                'package': {
                    'implementer': 'Maven',
                    'config': {
                        'pom-file': str(pom_file_path)
                    }
                }
            }
        }
        factory = TSSCFactory(config)
        with pytest.raises(ValueError):
            factory.run_step('package')
    def test_result(self, get_effective_pom_mock,
                    get_xml_element_by_path_mock):
        with TempDirectory() as test_dir:
            parent_work_dir_path = os.path.join(test_dir.path, 'working')

            pom_file_path = os.path.join(test_dir.path, 'pom.xml')
            step_config = {'pom-file': pom_file_path}

            step_implementer = self.create_step_implementer(
                step_config=step_config,
                parent_work_dir_path=parent_work_dir_path,
            )

            def get_effective_pom_side_effect():
                return '/does/not/matter/pom.xml'

            get_effective_pom_mock.side_effect = get_effective_pom_side_effect

            step_implementer._get_effective_pom_element('foo')
            get_effective_pom_mock.assert_called_once_with()
            get_xml_element_by_path_mock.assert_called_once_with(
                '/does/not/matter/pom.xml', 'foo', default_namespace='mvn')
Пример #16
0
    def test_run_step_pass(self):
        with TempDirectory() as temp_dir:
            parent_work_dir_path = os.path.join(temp_dir.path, 'working')
            repo = Repo.init(str(temp_dir.path))

            create_git_commit_with_sample_file(temp_dir, repo)

            step_config = {
                'repo-root': str(temp_dir.path)
            }

            step_implementer = self.create_step_implementer(
                step_config=step_config,
                step_name='generate-metadata',
                implementer='Git',
                parent_work_dir_path=parent_work_dir_path,
            )

            result = step_implementer._run_step()

            # cheating because we don't want to fully mock this yet
            self.assertTrue(result.success, True)
Пример #17
0
    def test_push_container_signature_specify_curl_implementer_missing_config_values(
            self):
        """Test for missing config values"""
        with TempDirectory() as temp_dir:
            config = TestStepImplementerSignContainerImageCurlPush.generate_config(
            )
            config['tssc-config']['sign-container-image']['config'] = {}
            expected_step_results = {
                'tssc-results': {
                    'sign-container-image': {}
                }
            }

            with self.assertRaisesRegex(
                    AssertionError,
                    r"The runtime step configuration \(\{\}\) is missing the required configuration "
                    r"keys \(\['container-image-signature-server-url', "
                    r"'container-image-signature-server-username', "
                    r"'container-image-signature-server-password'\]\)"):
                self.run_step_test_with_result_validation(
                    temp_dir, 'sign-container-image', config,
                    expected_step_results)
    def test_run_step_pass(self, git_repo_mock, git_url_mock):
        with TempDirectory() as temp_dir:
            tag = '1.0+69442c8'
            url = '[email protected]:ploigos/ploigos-step-runner.git'
            parent_work_dir_path = os.path.join(temp_dir.path, 'working')

            step_config = {
                'url': url,
                'git-username': '******',
                'git-password': '******',
                'version': tag
            }

            artifact_config = {
                'version': {'description': '', 'value': tag},
                'container-image-version': {'description': '', 'value': tag}
            }

            workflow_result = self.setup_previous_result(parent_work_dir_path, artifact_config)

            step_implementer = self.create_step_implementer(
                step_config=step_config,
                workflow_result=workflow_result,
                parent_work_dir_path=parent_work_dir_path,
            )

            git_url_mock.return_value = url

            result = step_implementer._run_step()

            expected_step_result = StepResult(step_name='tag-source', sub_step_name='Git', sub_step_implementer_name='Git')
            expected_step_result.add_artifact(name='tag', value=tag)

            # verifying all mocks were called
            git_url_mock.assert_called_once_with()
            git_repo_mock.create_tag.assert_called_once_with(tag, force=True)
            git_repo_mock.git.push.assert_called_once_with(url, '--tag')

            self.assertEqual(result, expected_step_result)
Пример #19
0
    def test_forward_slash_prefix(self):
        sample_file_path = os.path.join(
            os.path.dirname(__file__),
            'files',
            'sample.yaml'
        )

        with TempDirectory() as test_dir:
            destination_dir_path = os.path.join(test_dir.path, 'test_dest')
            actual_result = upload_file(
                file_path=sample_file_path,
                destination_uri=f"{destination_dir_path}"
            )

            expected_result = os.path.join(destination_dir_path, 'sample.yaml')
            self.assertEqual(expected_result, actual_result)

            with \
                open(actual_result, 'r') as uploaded_file, \
                open(sample_file_path, 'r') as original_file:

                self.assertEqual(original_file.read(), uploaded_file.read())
Пример #20
0
    def test__validate_required_config_or_previous_step_result_artifact_keys_invalid_missing_git_password(
            self):
        with TempDirectory() as test_dir:
            results_dir_path = os.path.join(test_dir.path,
                                            'step-runner-results')
            results_file_name = 'step-runner-results.yml'
            work_dir_path = os.path.join(test_dir.path, 'working')

            step_config = {'git-username': '******'}
            step_implementer = self.create_step_implementer(
                step_config=step_config,
                results_dir_path=results_dir_path,
                results_file_name=results_file_name,
                work_dir_path=work_dir_path,
            )

            with self.assertRaisesRegex(
                    StepRunnerException,
                    r"Either 'git-username' or 'git-password 'is not set. Neither or both must be set."
            ):
                step_implementer._validate_required_config_or_previous_step_result_artifact_keys(
                )
Пример #21
0
    def test_found_warning(self, mock_collect_report_results):
        with TempDirectory() as test_dir:
            # setup test
            actual_step_result = StepResult(
                step_name='mock-maven-test-step',
                sub_step_name='mock-maven-test-sub-step',
                sub_step_implementer_name=
                'MockMavenTestReportingMixinStepImplementer')
            test_report_dir = os.path.join(test_dir.path, 'mock-test-results')

            # setup mocks
            mock_collect_report_results.return_value = [{
                "time": 1.42,
                "tests": 42,
                "errors": 3,
                "skipped": 2,
                "failures": 1
            }, ['WARNING: mock warning about nothing']]

            # run test
            MavenTestReportingMixin._gather_evidence_from_test_report_directory_testsuite_elements(
                step_result=actual_step_result,
                test_report_dirs=test_report_dir)

            # verify results
            expected_step_result = StepResult(
                step_name='mock-maven-test-step',
                sub_step_name='mock-maven-test-sub-step',
                sub_step_implementer_name=
                'MockMavenTestReportingMixinStepImplementer')
            expected_step_result.message = '\nWARNING: mock warning about nothing'
            expected_step_result.add_evidence(name='time', value=1.42)
            expected_step_result.add_evidence(name='tests', value=42)
            expected_step_result.add_evidence(name='errors', value=3)
            expected_step_result.add_evidence(name='skipped', value=2)
            expected_step_result.add_evidence(name='failures', value=1)
            self.assertEqual(actual_step_result, expected_step_result)
            mock_collect_report_results.assert_called_once_with(
                test_report_dirs=[test_report_dir])
    def test_post_process_content2(self):
        self.file_converter._file_content = '<head><meta title="this is test2"/><meta not_valid="not_in_schema"/></head><p><input checked="" type="checkbox"/>Check 1</p><p><input type="checkbox"/>Check 2</p><img src="filepath/image.png" width="600"><p><iframe allowfullscreen="" anchorhref="https://www.youtube.com/watch?v=SqdxNUMO2cg" frameborder="0" height="315" src="https://www.youtube.com/embed/SqdxNUMO2cg" width="420" youtube="true"> </iframe></p>'
        self.file_converter._metadata_schema = ['title']
        self.file_converter._file = Path('a-file.html')
        self.file_converter._conversion_settings.export_format = 'pandoc_markdown'
        self.file_converter._conversion_settings.conversion_input = 'html'
        with TempDirectory() as d:
            self.file_converter._conversion_settings.source = Path(d.path)
            self.file_converter._conversion_settings.export_folder = Path(d.path)
            self.file_converter.pre_process_content()
            self.file_converter.convert_content()

            # set toml and confirm content is forced back into yaml
            self.file_converter._metadata_processor._conversion_settings.front_matter_format = 'toml'

            self.file_converter.post_process_content()

            self.assertEqual(
                '---\ntitle: this is test2\n---\n\n- [x] Check 1\n\n- [ ] Check 2\n\n<img src="filepath/image.png" width="600" />\n\n\n<iframe allowfullscreen="" anchorhref="https://www.youtube.com/watch?v=SqdxNUMO2cg" frameborder="0" height="315" src="https://www.youtube.com/embed/SqdxNUMO2cg" width="420" youtube="true"> </iframe>\n\n',
                self.file_converter._post_processed_content,
                'post processing failed'
                )
    def test_run_step_pass(self):
        with TempDirectory() as temp_dir:
            results_dir_path = os.path.join(temp_dir.path, 'step-runner-results')
            results_file_name = 'step-runner-results.yml'
            work_dir_path = os.path.join(temp_dir.path, 'working')
            test_file_name = 'yamlnotused'
            test_file_path = os.path.join(temp_dir.path, test_file_name)
            temp_dir.write(test_file_path, b'ignored')

            step_config = {}
            artifact_config = {
                'argocd-deployed-manifest': {
                    'value': test_file_path
                }
            }
            self.setup_previous_result(work_dir_path, artifact_config)

            step_implementer = self.create_step_implementer(
                step_config=step_config,
                step_name='validate-environment-configuration',
                implementer='ConfiglintArgocd',
                results_dir_path=results_dir_path,
                results_file_name=results_file_name,
                work_dir_path=work_dir_path,
            )

            result = step_implementer._run_step()

            expected_step_result = StepResult(
                step_name='validate-environment-configuration',
                sub_step_name='ConfiglintArgocd',
                sub_step_implementer_name='ConfiglintArgocd'
            )

            expected_step_result.add_artifact(
                name='configlint-yml-path',
                value=test_file_path
            )
            self.assertEqual(expected_step_result.get_step_result_dict(), result.get_step_result_dict())
Пример #24
0
    def test_with_docker_file(self):
        """Test with docker_file provided."""
        client = make_fake_client()
        with TempDirectory() as tmp_dir:
            docker_file = tmp_dir.write('Dockerfile', b'')
            dockerized_pip(os.getcwd(), client=client, docker_file=docker_file)

            client.api.build.assert_called_with(path=tmp_dir.path,
                                                dockerfile='Dockerfile',
                                                forcerm=True)
            client.api.create_container.assert_called_with(
                detach=True,
                image=FAKE_IMAGE_ID,
                command=self.command,
                host_config=self.host_config)
            client.api.inspect_container.assert_called_with(FAKE_CONTAINER_ID)
            client.api.start.assert_called_with(FAKE_CONTAINER_ID)
            client.api.logs.assert_called_with(FAKE_CONTAINER_ID,
                                               stderr=True,
                                               stdout=True,
                                               stream=True,
                                               tail=0)
Пример #25
0
    def test_add_config_dir_one_valid_file(self):
        with TempDirectory() as temp_dir:
            config_dir = "test"

            config_files = [{
                'name': os.path.join(config_dir, 'foo.yml'),
                'contents': {
                    Config.CONFIG_KEY: {}
                }
            }]

            for config_file in config_files:
                config_file_name = config_file['name']
                config_file_contents = config_file['contents']
                temp_dir.write(config_file_name,
                               bytes(f"{config_file_contents}", 'utf-8'))

            config = Config()
            config.add_config(os.path.join(temp_dir.path, config_dir))

            self.assertEqual(config.global_defaults, {})
            self.assertEqual(config.global_environment_defaults, {})
Пример #26
0
    def test_run_shell_command(self, os_path_exists_mock,
                               tox_shell_command_mock):

        # Given a working directory
        with TempDirectory() as temp_dir:
            working_dir_path = os.path.join(temp_dir.path, 'working')

            # Given an ToxLint step implementer
            tox_test = self.create_given_step_implementer(
                ToxLint, parent_work_dir_path=working_dir_path)

            # When I run the step
            tox_test.run_step()

            # Then it should run a shell command, 'tox lint'
            tox_shell_command_mock.assert_any_call((
                '-q',
                '-e',
                'lint',
            ),
                                                   _out=Any(StringIO),
                                                   _err=Any(StringIO))
Пример #27
0
    def test_success_but_no_tests(self, mock_effective_pom_element,
                                  mock_write_working_file,
                                  mock_run_maven_step):
        with TempDirectory() as test_dir:
            parent_work_dir_path = os.path.join(test_dir.path, 'working')

            pom_file = os.path.join(test_dir.path, 'mock-pom.xml')
            step_config = {'pom-file': pom_file, 'fail-on-no-tests': False}
            step_implementer = self.create_step_implementer(
                step_config=step_config,
                parent_work_dir_path=parent_work_dir_path,
            )

            # run step
            actual_step_result = step_implementer._run_step()

            # create expected step result
            surefire_reports_dir = os.path.join(test_dir.path,
                                                'target/surefire-reports')
            expected_step_result = StepResult(
                step_name='unit-test',
                sub_step_name='MavenTest',
                sub_step_implementer_name='MavenTest')
            expected_step_result.message = "No unit tests defined, but 'fail-on-no-tests' is False."
            expected_step_result.add_artifact(
                description="Standard out and standard error from maven.",
                name='maven-output',
                value='/mock/mvn_output.txt')
            expected_step_result.add_artifact(
                description="Surefire reports generated by maven.",
                name='surefire-reports',
                value=surefire_reports_dir)

            # verify step result
            self.assertEqual(actual_step_result, expected_step_result)

            mock_write_working_file.assert_called_once()
            mock_run_maven_step.assert_called_with(
                mvn_output_file_path='/mock/mvn_output.txt')
    def test_pom_file_does_not_exist(self, mock_super_validate):
        with TempDirectory() as test_dir:
            parent_work_dir_path = os.path.join(test_dir.path, 'working')

            pom_file_path = '/does/not/exist/pom.xml'
            step_config = {
                'pom-file': pom_file_path,
                'maven-phases-and-goals': 'fake-phase'
            }

            step_implementer = self.create_step_implementer(
                step_config=step_config,
                parent_work_dir_path=parent_work_dir_path,
            )

            with self.assertRaisesRegex(
                    AssertionError,
                    rf'Given maven pom file \(pom-file\) does not exist: {pom_file_path}'
            ):
                step_implementer._validate_required_config_or_previous_step_result_artifact_keys(
                )
                mock_super_validate.assert_called_once_with()
Пример #29
0
 def test_push_artifact_with_artifacts_missing_from_results(self, mvn_mock):
     with TempDirectory() as temp_dir:
         temp_dir.makedir('tssc-results')
         temp_dir.write('tssc-results/tssc-results.yml', b'''tssc-results:
           generate-metadata:
             version: 1.0-123abc
           ''')
         config = {
            'tssc-config': {
                'global-defaults': {
                    'maven-servers': [
                        {'id': 'ID1', 'username': '******', 'password': '******'},
                        {'id': 'ID2'}
                    ],
                    'maven-repositories': [
                        {'id': 'ID1', 'url': 'URL1', 'snapshots': 'true', 'releases': 'false'},
                        {'id': 'ID2', 'url': 'URL2'}
                    ],
                    'maven-mirrors': [
                        {'id': 'ID1', 'url': 'URL1', 'mirror-of': '*'},
                        {'id': 'ID2', 'url': 'URL2', 'mirror-of': '*'}
                    ],
                },
                'push-artifacts': {
                     'implementer': 'Maven',
                     'config': {
                         'maven-push-artifact-repo-id': 'repoid',
                         'maven-push-artifact-repo-url': 'repourl'
                     }
                 }
             }
         }
         runtime_args = {}
         expected_step_results = {}
         with self.assertRaisesRegex(
                 ValueError,
                 'package results missing artifacts'):
             run_step_test_with_result_validation(temp_dir, 'push-artifacts',
                                                  config, expected_step_results, runtime_args)
Пример #30
0
    def test_fail_maven_run(self, mock_write_working_file,
                            mock_run_maven_step):
        with TempDirectory() as test_dir:
            parent_work_dir_path = os.path.join(test_dir.path, 'working')

            pom_file = os.path.join(test_dir.path, 'mock-pom.xml')
            step_config = {'pom-file': pom_file}
            step_implementer = self.create_step_implementer(
                step_config=step_config,
                parent_work_dir_path=parent_work_dir_path,
            )

            # run step with mock failure
            mock_run_maven_step.side_effect = StepRunnerException(
                'Mock error running maven')
            actual_step_result = step_implementer._run_step()

            # create expected step result
            surefire_reports_dir = os.path.join(test_dir.path,
                                                'target/surefire-reports')
            expected_step_result = StepResult(
                step_name='package',
                sub_step_name='MavenPackage',
                sub_step_implementer_name='MavenPackage')
            expected_step_result.success = False
            expected_step_result.message = "Error running 'maven package' to package artifacts. " \
                "More details maybe found in 'maven-output' report artifact: " \
                "Mock error running maven"
            expected_step_result.add_artifact(
                description="Standard out and standard error from maven.",
                name='maven-output',
                value='/mock/mvn_output.txt')

            # verify step result
            self.assertEqual(actual_step_result, expected_step_result)

            mock_write_working_file.assert_called_once()
            mock_run_maven_step.assert_called_with(
                mvn_output_file_path='/mock/mvn_output.txt')