How to use test_targets method in green

Best Python code snippet using green

gyptest-analyzer.py

Source: gyptest-analyzer.py Github

copy

Full Screen

1#!/​usr/​bin/​env python2# Copyright (c) 2014 Google Inc. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5"""Tests for analyzer6"""7import json8import TestGyp9found = 'Found dependency'10found_all = 'Found dependency (all)'11not_found = 'No dependencies'12def _CreateConfigFile(files, additional_compile_targets, test_targets=[]):13 """Creates the analyzer config file, which is used as the input to analyzer.14 See description of analyzer.py for description of the arguments."""15 f = open('test_file', 'w')16 to_write = {'files': files,17 'test_targets': test_targets,18 'additional_compile_targets': additional_compile_targets }19 json.dump(to_write, f)20 f.close()21def _CreateBogusConfigFile():22 f = open('test_file','w')23 f.write('bogus')24 f.close()25def _ReadOutputFileContents():26 f = open('analyzer_output', 'r')27 result = json.load(f)28 f.close()29 return result30# NOTE: this would be clearer if it subclassed TestGypCustom, but that trips31# over a bug in pylint (E1002).32test = TestGyp.TestGypCustom(format='analyzer')33def CommonArgs():34 return ('-Gconfig_path=test_file',35 '-Ganalyzer_output_path=analyzer_output')36def run_analyzer(*args, **kw):37 """Runs the test specifying a particular config and output path."""38 args += CommonArgs()39 test.run_gyp('test.gyp', *args, **kw)40def run_analyzer2(*args, **kw):41 """Same as run_analyzer(), but passes in test2.gyp instead of test.gyp."""42 args += CommonArgs()43 test.run_gyp('test2.gyp', *args, **kw)44def run_analyzer3(*args, **kw):45 """Same as run_analyzer(), but passes in test3.gyp instead of test.gyp."""46 args += CommonArgs()47 test.run_gyp('test3.gyp', *args, **kw)48def run_analyzer4(*args, **kw):49 """Same as run_analyzer(), but passes in test3.gyp instead of test.gyp."""50 args += CommonArgs()51 test.run_gyp('test4.gyp', *args, **kw)52def EnsureContains(matched=False, compile_targets=set(), test_targets=set()):53 """Verifies output contains |compile_targets|."""54 result = _ReadOutputFileContents()55 if 'error' in result:56 print 'unexpected error', result.get('error')57 test.fail_test()58 if 'invalid_targets' in result:59 print 'unexpected invalid_targets', result.get('invalid_targets')60 test.fail_test()61 actual_compile_targets = set(result['compile_targets'])62 if actual_compile_targets != compile_targets:63 print 'actual compile_targets:', actual_compile_targets, \64 '\nexpected compile_targets:', compile_targets65 test.fail_test()66 actual_test_targets = set(result['test_targets'])67 if actual_test_targets != test_targets:68 print 'actual test_targets:', actual_test_targets, \69 '\nexpected test_targets:', test_targets70 test.fail_test()71 if matched and result['status'] != found:72 print 'expected', found, 'got', result['status']73 test.fail_test()74 elif not matched and result['status'] != not_found:75 print 'expected', not_found, 'got', result['status']76 test.fail_test()77def EnsureMatchedAll(compile_targets, test_targets=set()):78 result = _ReadOutputFileContents()79 if 'error' in result:80 print 'unexpected error', result.get('error')81 test.fail_test()82 if 'invalid_targets' in result:83 print 'unexpected invalid_targets', result.get('invalid_targets')84 test.fail_test()85 if result['status'] != found_all:86 print 'expected', found_all, 'got', result['status']87 test.fail_test()88 actual_compile_targets = set(result['compile_targets'])89 if actual_compile_targets != compile_targets:90 print ('actual compile_targets:', actual_compile_targets,91 '\nexpected compile_targets:', compile_targets)92 test.fail_test()93 actual_test_targets = set(result['test_targets'])94 if actual_test_targets != test_targets:95 print ('actual test_targets:', actual_test_targets,96 '\nexpected test_targets:', test_targets)97 test.fail_test()98def EnsureError(expected_error_string):99 """Verifies output contains the error string."""100 result = _ReadOutputFileContents()101 if result.get('error', '').find(expected_error_string) == -1:102 print 'actual error:', result.get('error', ''), '\nexpected error:', \103 expected_error_string104 test.fail_test()105def EnsureStdoutContains(expected_error_string):106 if test.stdout().find(expected_error_string) == -1:107 print 'actual stdout:', test.stdout(), '\nexpected stdout:', \108 expected_error_string109 test.fail_test()110def EnsureInvalidTargets(expected_invalid_targets):111 """Verifies output contains invalid_targets."""112 result = _ReadOutputFileContents()113 actual_invalid_targets = set(result['invalid_targets'])114 if actual_invalid_targets != expected_invalid_targets:115 print 'actual invalid_targets:', actual_invalid_targets, \116 '\nexpected :', expected_invalid_targets117 test.fail_test()118# Two targets, A and B (both static_libraries) and A depends upon B. If a file119# in B changes, then both A and B are output. It is not strictly necessary that120# A is compiled in this case, only B.121_CreateConfigFile(['b.c'], ['all'])122test.run_gyp('static_library_test.gyp', *CommonArgs())123EnsureContains(matched=True, compile_targets={'a' ,'b'})124# Verifies config_path must be specified.125test.run_gyp('test.gyp')126EnsureStdoutContains('Must specify files to analyze via config_path')127# Verifies config_path must point to a valid file.128test.run_gyp('test.gyp', '-Gconfig_path=bogus_file',129 '-Ganalyzer_output_path=analyzer_output')130EnsureError('Unable to open file bogus_file')131# Verify 'invalid_targets' is present when bad target is specified.132_CreateConfigFile(['exe2.c'], ['bad_target'])133run_analyzer()134EnsureInvalidTargets({'bad_target'})135# Verifies config_path must point to a valid json file.136_CreateBogusConfigFile()137run_analyzer()138EnsureError('Unable to parse config file test_file')139# Trivial test of a source.140_CreateConfigFile(['foo.c'], ['all'])141run_analyzer()142EnsureContains(matched=True, compile_targets={'exe'})143# Conditional source that is excluded.144_CreateConfigFile(['conditional_source.c'], ['all'])145run_analyzer()146EnsureContains(matched=False)147# Conditional source that is included by way of argument.148_CreateConfigFile(['conditional_source.c'], ['all'])149run_analyzer('-Dtest_variable=1')150EnsureContains(matched=True, compile_targets={'exe'})151# Two unknown files.152_CreateConfigFile(['unknown1.c', 'unoknow2.cc'], ['all'])153run_analyzer()154EnsureContains()155# Two unknown files.156_CreateConfigFile(['unknown1.c', 'subdir/​subdir_sourcex.c'], ['all'])157run_analyzer()158EnsureContains()159# Included dependency160_CreateConfigFile(['unknown1.c', 'subdir/​subdir_source.c'], ['all'])161run_analyzer()162EnsureContains(matched=True, compile_targets={'exe', 'exe3'})163# Included inputs to actions.164_CreateConfigFile(['action_input.c'], ['all'])165run_analyzer()166EnsureContains(matched=True, compile_targets={'exe'})167# Don't consider outputs.168_CreateConfigFile(['action_output.c'], ['all'])169run_analyzer()170EnsureContains(matched=False)171# Rule inputs.172_CreateConfigFile(['rule_input.c'], ['all'])173run_analyzer()174EnsureContains(matched=True, compile_targets={'exe'})175# Ignore path specified with PRODUCT_DIR.176_CreateConfigFile(['product_dir_input.c'], ['all'])177run_analyzer()178EnsureContains(matched=False)179# Path specified via a variable.180_CreateConfigFile(['subdir/​subdir_source2.c'], ['all'])181run_analyzer()182EnsureContains(matched=True, compile_targets={'exe'})183# Verifies paths with /​/​ are fixed up correctly.184_CreateConfigFile(['parent_source.c'], ['all'])185run_analyzer()186EnsureContains(matched=True, compile_targets={'exe', 'exe3'})187# Verifies relative paths are resolved correctly.188_CreateConfigFile(['subdir/​subdir_source.h'], ['all'])189run_analyzer()190EnsureContains(matched=True, compile_targets={'exe'})191# Verifies relative paths in inputs are resolved correctly.192_CreateConfigFile(['rel_path1.h'], ['all'])193run_analyzer()194EnsureContains(matched=True, compile_targets={'exe'})195# Various permutations when passing in targets.196_CreateConfigFile(['exe2.c', 'subdir/​subdir2b_source.c'],197 ['all'], ['exe', 'exe3'])198run_analyzer()199EnsureContains(matched=True, test_targets={'exe3'},200 compile_targets={'exe2', 'exe3'})201_CreateConfigFile(['exe2.c', 'subdir/​subdir2b_source.c'], ['all'], ['exe'])202run_analyzer()203EnsureContains(matched=True, compile_targets={'exe2', 'exe3'})204# Verifies duplicates are ignored.205_CreateConfigFile(['exe2.c', 'subdir/​subdir2b_source.c'], ['all'],206 ['exe', 'exe'])207run_analyzer()208EnsureContains(matched=True, compile_targets={'exe2', 'exe3'})209_CreateConfigFile(['exe2.c'], ['all'], ['exe'])210run_analyzer()211EnsureContains(matched=True, compile_targets={'exe2'})212_CreateConfigFile(['exe2.c'], ['all'])213run_analyzer()214EnsureContains(matched=True, compile_targets={'exe2'})215_CreateConfigFile(['subdir/​subdir2b_source.c', 'exe2.c'], ['all'])216run_analyzer()217EnsureContains(matched=True, compile_targets={'exe2', 'exe3'})218_CreateConfigFile(['subdir/​subdir2b_source.c'], ['all'], ['exe3'])219run_analyzer()220EnsureContains(matched=True, test_targets={'exe3'}, compile_targets={'exe3'})221_CreateConfigFile(['exe2.c'], ['all'])222run_analyzer()223EnsureContains(matched=True, compile_targets={'exe2'})224_CreateConfigFile(['foo.c'], ['all'])225run_analyzer()226EnsureContains(matched=True, compile_targets={'exe'})227# Assertions when modifying build (gyp/​gypi) files, especially when said files228# are included.229_CreateConfigFile(['subdir2/​d.cc'], ['all'], ['exe', 'exe2', 'foo', 'exe3'])230run_analyzer2()231EnsureContains(matched=True, test_targets={'exe', 'foo'},232 compile_targets={'exe', 'foo'})233_CreateConfigFile(['subdir2/​subdir.includes.gypi'], ['all'],234 ['exe', 'exe2', 'foo', 'exe3'])235run_analyzer2()236EnsureContains(matched=True, test_targets={'exe', 'foo'},237 compile_targets={'exe', 'foo'})238_CreateConfigFile(['subdir2/​subdir.gyp'], ['all'],239 ['exe', 'exe2', 'foo', 'exe3'])240run_analyzer2()241EnsureContains(matched=True, test_targets={'exe', 'foo'},242 compile_targets={'exe', 'foo'})243_CreateConfigFile(['test2.includes.gypi'], ['all'],244 ['exe', 'exe2', 'foo', 'exe3'])245run_analyzer2()246EnsureContains(matched=True, test_targets={'exe', 'exe2', 'exe3'},247 compile_targets={'exe', 'exe2', 'exe3'})248# Verify modifying a file included makes all targets dirty.249_CreateConfigFile(['common.gypi'], ['all'], ['exe', 'exe2', 'foo', 'exe3'])250run_analyzer2('-Icommon.gypi')251EnsureMatchedAll({'all', 'exe', 'exe2', 'foo', 'exe3'},252 {'exe', 'exe2', 'foo', 'exe3'})253# Assertions from test3.gyp.254_CreateConfigFile(['d.c', 'f.c'], ['all'], ['a'])255run_analyzer3()256EnsureContains(matched=True, test_targets={'a'}, compile_targets={'a', 'b'})257_CreateConfigFile(['f.c'], ['all'], ['a'])258run_analyzer3()259EnsureContains(matched=True, test_targets={'a'}, compile_targets={'a', 'b'})260_CreateConfigFile(['f.c'], ['all'])261run_analyzer3()262EnsureContains(matched=True, compile_targets={'a', 'b'})263_CreateConfigFile(['c.c', 'e.c'], ['all'])264run_analyzer3()265EnsureContains(matched=True, compile_targets={'a', 'b', 'c', 'e'})266_CreateConfigFile(['d.c'], ['all'], ['a'])267run_analyzer3()268EnsureContains(matched=True, test_targets={'a'}, compile_targets={'a', 'b'})269_CreateConfigFile(['a.c'], ['all'], ['a', 'b'])270run_analyzer3()271EnsureContains(matched=True, test_targets={'a'}, compile_targets={'a'})272_CreateConfigFile(['a.c'], ['all'], ['a', 'b'])273run_analyzer3()274EnsureContains(matched=True, test_targets={'a'}, compile_targets={'a'})275_CreateConfigFile(['d.c'], ['all'], ['a', 'b'])276run_analyzer3()277EnsureContains(matched=True, test_targets={'a', 'b'},278 compile_targets={'a', 'b'})279_CreateConfigFile(['f.c'], ['all'], ['a'])280run_analyzer3()281EnsureContains(matched=True, test_targets={'a'}, compile_targets={'a', 'b'})282_CreateConfigFile(['a.c'], ['all'], ['a'])283run_analyzer3()284EnsureContains(matched=True, test_targets={'a'}, compile_targets={'a'})285_CreateConfigFile(['a.c'], ['all'])286run_analyzer3()287EnsureContains(matched=True, compile_targets={'a'})288_CreateConfigFile(['d.c'], ['all'])289run_analyzer3()290EnsureContains(matched=True, compile_targets={'a', 'b'})291# Assertions around test4.gyp.292_CreateConfigFile(['f.c'], ['all'])293run_analyzer4()294EnsureContains(matched=True, compile_targets={'e', 'f'})295_CreateConfigFile(['d.c'], ['all'])296run_analyzer4()297EnsureContains(matched=True, compile_targets={'a', 'b', 'c', 'd'})298_CreateConfigFile(['i.c'], ['all'])299run_analyzer4()300EnsureContains(matched=True, compile_targets={'h', 'i'})301# Assertions where 'all' is not supplied in compile_targets.302_CreateConfigFile(['exe2.c'], [], ['exe2'])303run_analyzer()304EnsureContains(matched=True, test_targets={'exe2'}, compile_targets={'exe2'})305_CreateConfigFile(['exe20.c'], [], ['exe2'])306run_analyzer()307EnsureContains(matched=False)308_CreateConfigFile(['exe2.c', 'exe3.c'], [], ['exe2', 'exe3'])309run_analyzer()310EnsureContains(matched=True, test_targets={'exe2', 'exe3'},311 compile_targets={'exe2', 'exe3'})312_CreateConfigFile(['exe2.c', 'exe3.c'], ['exe3'], ['exe2'])313run_analyzer()314EnsureContains(matched=True, test_targets={'exe2'},315 compile_targets={'exe2', 'exe3'})316_CreateConfigFile(['exe3.c'], ['exe2'], ['exe2'])317run_analyzer()318EnsureContains(matched=False)319# Assertions with 'all' listed as a test_target.320_CreateConfigFile(['exe3.c'], [], ['all'])321run_analyzer()322EnsureContains(matched=True, compile_targets={'exe3', 'all'},323 test_targets={'all'})324_CreateConfigFile(['exe2.c'], [], ['all', 'exe2'])325run_analyzer()326EnsureContains(matched=True, compile_targets={'exe2', 'all'},327 test_targets={'all', 'exe2'})...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Playwright End To End Testing Tutorial: A Complete Guide

It is essential for a team, when speaking about test automation, to take the time needed to think, analyze and try what will be the best tool, framework, and language that suits your team’s needs.

How To Build An Automated Testing Pipeline With CircleCI & Selenium Grid

In this digital era, Continuous Integration and Continuous Deployment is closely aligned with software development and agile methodologies. Organizations deploy latest versions of software products every minute to ensure maximum competitive edge.

Code Coverage vs Test Coverage: Which Is Better?

Test Coverage and Code coverage are the most popular methodologies for measuring the effectiveness of the code. Though these terms are sometimes used interchangeably since their underlying principles are the same. But they are not as similar as you may think. Many times, I have noticed the testing team and development team being confused over the use of these two terminologies. Which is why I thought of coming up with an article to talk about the differences between code coverage and test coverage in detail.

Cross Browser Testing Checklist Before Going Live

When someone develops a website, going live it’s like a dream come true. I have also seen one of my friends so excited as he was just about to launch his website. When he finally hit the green button, some unusual trend came suddenly into his notice. After going into details, he found out that the website has a very high bounce rate on Mobile devices. Thanks to Google Analytics, he was able to figure that out.

Top 9 PHP Frameworks For Web Development In 2021

With an average global salary of $39k, PHP is one of the most popular programming languages in the developer community. It’s the language behind the most popular CMS, WordPress. It is in-use by 79% of total websites globally, including the most used social network- Facebook, the largest digital encyclopedia – Wikipedia, China’s news giant Xinhuanet, and Russia’s social network VK.com.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run green automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful