def testMatrixAndRegexFlags(): yaml_contents = dedent(''' platform-win.*:junit_patterns: - "junit*.xml" platform-(?!windows):build_shell_commands: - "{platform} command" matrix: platform: - linux - windows ''') for jd_file in JobsDoneJob.CreateFromYAML(yaml_contents, repository=_REPOSITORY): if jd_file.matrix_row['platform'] == 'linux': assert jd_file.junit_patterns is None assert jd_file.build_batch_commands is None assert jd_file.build_shell_commands == ['linux command'] else: assert jd_file.junit_patterns == ['junit*.xml'] assert jd_file.build_shell_commands is None
def GetJobsFromFile(repository, jobs_done_file_contents): ''' Creates jobs from repository information and a jobs_done file. :param Repository repository: .. seealso:: Repository :param unicode|None jobs_done_file_contents: .. seealso:: JobsDoneJob.CreateFromYAML :return set(JenkinsJob) ''' from jobs_done10.job_generator import JobGeneratorConfigurator from jobs_done10.jobs_done_job import JobsDoneJob jenkins_generator = JenkinsXmlJobGenerator() jobs = [] jobs_done_jobs = JobsDoneJob.CreateFromYAML(jobs_done_file_contents, repository) for jobs_done_job in jobs_done_jobs: JobGeneratorConfigurator.Configure(jenkins_generator, jobs_done_job) jobs.append(jenkins_generator.GetJob()) return jobs
def testCreateJobsDoneJobFromYAML(): yaml_contents = dedent(''' junit_patterns: - "junit*.xml" boosttest_patterns: - "cpptest*.xml" display_name: "[{branch}] {planet}-{moon} {name}" label_expression: "planet-{planet}&&moon-{moon}" parameters: - choice: name: "PARAM" choices: - "choice_1" - "choice_2" description: "Description" build_batch_commands: - "command on planet {planet} (repository '{name}' on '{branch}')" matrix: planet: - mercury - venus moon: - europa ''') jobs_done_jobs = JobsDoneJob.CreateFromYAML(yaml_contents, repository=_REPOSITORY) # Two possible jobs based on matrix (mercury and venus) assert len(jobs_done_jobs) == 2 def CheckCommonValues(jobs_done_job): assert jobs_done_job.matrix == { 'moon': ['europa'], 'planet': ['mercury', 'venus'] } assert jobs_done_job.junit_patterns == ['junit*.xml'] assert jobs_done_job.boosttest_patterns == ['cpptest*.xml'] assert jobs_done_job.parameters == [{ 'choice': { 'name': 'PARAM', 'choices': ['choice_1', 'choice_2'], 'description': 'Description', } }] CheckCommonValues(jobs_done_jobs[0]) CheckCommonValues(jobs_done_jobs[1]) # Tests for specific jobs mercury_job = jobs_done_jobs[0] if jobs_done_jobs[0].matrix_row[ 'planet'] == 'mercury' else jobs_done_jobs[1] venus_job = jobs_done_jobs[0] if jobs_done_jobs[0].matrix_row[ 'planet'] == 'venus' else jobs_done_jobs[1] assert mercury_job.matrix == { 'moon': ['europa'], 'planet': ['mercury', 'venus'] } assert mercury_job.matrix_row == {'moon': 'europa', 'planet': 'mercury'} assert venus_job.matrix == { 'moon': ['europa'], 'planet': ['mercury', 'venus'] } assert venus_job.matrix_row == {'moon': 'europa', 'planet': 'venus'} # In this case, our commands use some replacement variables, including variables defined in # 'matrix', and special cases 'name' and 'branch' based on repository. assert mercury_job.build_batch_commands == [ "command on planet mercury (repository 'space' on 'milky_way')" ] assert venus_job.build_batch_commands == [ "command on planet venus (repository 'space' on 'milky_way')" ] # Check display_name assert mercury_job.display_name == '[milky_way] mercury-europa space' assert mercury_job.label_expression == 'planet-mercury&&moon-europa' # Check labels assert venus_job.display_name == '[milky_way] venus-europa space' assert venus_job.label_expression == 'planet-venus&&moon-europa'
def testExclude(): key = lambda job: ':'.join(j + '-' + job.matrix_row[j] for j in sorted(job.matrix_row.keys())) # Base case ------------------------------------------------------------------------------------ yaml_contents = dedent(''' matrix: planet: - mercury - venus moon: - europa - ganymede ''') jobs_done_jobs = JobsDoneJob.CreateFromYAML(yaml_contents, repository=_REPOSITORY) assert sorted(map(key, jobs_done_jobs)) == [ 'moon-europa:planet-mercury', 'moon-europa:planet-venus', 'moon-ganymede:planet-mercury', 'moon-ganymede:planet-venus' ] # Exclude everything matching planet-venus ----------------------------------------------------- yaml_contents = dedent(''' matrix: planet: - mercury - venus moon: - europa - ganymede planet-venus:exclude: yes ''') jobs_done_jobs = JobsDoneJob.CreateFromYAML(yaml_contents, repository=_REPOSITORY) assert sorted(map(key, jobs_done_jobs)) == [ 'moon-europa:planet-mercury', 'moon-ganymede:planet-mercury', ] # Exclude everything matching planet-venus and moon europa ------------------------------------- yaml_contents = dedent(''' matrix: planet: - mercury - venus moon: - europa - ganymede planet-venus:moon-europa:exclude: yes ''') jobs_done_jobs = JobsDoneJob.CreateFromYAML(yaml_contents, repository=_REPOSITORY) assert sorted(map(key, jobs_done_jobs)) == [ 'moon-europa:planet-mercury', 'moon-ganymede:planet-mercury', 'moon-ganymede:planet-venus' ] # Exclude everything --------------------------------------------------------------------------- yaml_contents = dedent(''' matrix: planet: - mercury - venus moon: - europa - ganymede exclude: yes ''') jobs_done_jobs = JobsDoneJob.CreateFromYAML(yaml_contents, repository=_REPOSITORY) assert sorted(map(key, jobs_done_jobs)) == []