How to use generate_script method in ATX

Best Python code snippet using ATX

command_controller.py

Source: command_controller.py Github

copy

Full Screen

...23 def get_global(self, key: str):24 if key in self.globals:25 return self.globals[key]26 return ''27 def generate_script(self, key: str, directory_name: str):28 template_name = self.get_global('template')29 file_name = self.get_global('file_name')30 output_directory = verify_directory(self.get_global('output_directory'))31 if template_name == '':32 template_name = 'standard'33 34 if file_name == '':35 file_name = 'standard_script'36 37 template_name_and_path = 'templates/​' + self.templates[template_name][0]38 config_file = 'configuration/​' + self.templates[template_name][1]39 40 if not isfile(template_name_and_path) or not isfile(config_file):41 return42 with open(template_name_and_path, 'r') as file_template:43 template = file_template.read()44 with open(config_file, 'r', encoding='utf-8') as f:45 json_data = json.load(f)46 47 placeholder = {}48 placeholder['custom_join'] = ''49 placeholder['custom_condition'] = ''50 try:51 for node in json_data[key]: 52 placeholder[node] = format_data(node, str(json_data[key][node]))53 54 except KeyError:55 print(f'Key: {key} not found')56 return57 58 if 'pool_language' in json_data[key]:59 language_file = f'configuration/​language/​{key}.txt'60 if os.path.isfile(language_file):61 with open(language_file) as f:62 placeholder['pool_language'] = f.read()63 if 'salutation' in json_data[key]:64 salutation_file = f'configuration/​salutation/​{key}.txt'65 if os.path.isfile(salutation_file):66 with open(salutation_file) as f:67 placeholder['salutation'] = f.read()68 # Look for custom scripts and apply them if found69 custom_join_file = self.get_global('custom_join')70 if custom_join_file == '':71 custom_join_file = 'custom/​custom_join.txt'72 73 if os.path.isfile(custom_join_file):74 with open(custom_join_file) as f:75 placeholder['custom_join'] = f.read()76 custom_condition_file = 'custom/​' + self.get_global('custom_condition')77 if custom_condition_file == '' or custom_condition_file == 'custom/​':78 custom_condition_file = 'custom/​custom_condition.txt'79 80 if os.path.isfile(custom_condition_file):81 with open(custom_condition_file) as f:82 placeholder['custom_condition'] = f.read()83 generated_script = replace_placeholder(placeholder, template, key)84 85 directory_path = f'{output_directory}\\{directory_name}\\'86 if not os.path.isdir(directory_path):87 os.makedirs(directory_path)88 file_name_and_path = f'{output_directory}\\{directory_name}\\{file_name}_{key}.sql'89 if os.path.isfile(file_name_and_path):90 os.remove(file_name_and_path)91 with open(file_name_and_path, 'w') as f:92 f.write(generated_script)93 print(f'Script generated in {os.path.abspath(directory_path)}')94 def auto_config(self):95 files = os.listdir('custom/​auto/​')96 for file in files:97 config_file = 'custom/​auto/​' + file98 with open(config_file, 'r') as f:99 config_file_contents = json.load(f)100 for node in config_file_contents:101 self.set_global('template', node['template'])102 self.set_global('output_directory', node['output_directory'])103 self.set_global('file_name', node['file_name'])104 self.set_global('custom_join', node['custom_join'])105 self.set_global('custom_condition', node['custom_condition'])106 107 print('Generating scripts from auto config ...')108 for market in node['market'].split(','):109 the_market = market.strip().upper()110 self.generate_script(key=the_market, directory_name='autoconfig')111 print(f'{the_market} done ...')112 print('... Complete')113 def meia(self):114 directory = 'MEIA'115 print('Generating scripts for MEIA ...')116 print()117 self.generate_script(key='UAE', directory_name=directory)118 print('UAE done ...')119 self.generate_script(key='KSA', directory_name=directory)120 print('KSA done ...')121 self.generate_script(key='IND', directory_name=directory)122 print('IND done ...')123 print()124 print('... Complete')125 def europe(self):126 directory = 'Europe'127 print('Generating scripts for Europe ...')128 print()129 130 self.generate_script(key='BESC', directory_name=directory)131 print('BESC done ...')132 self.generate_script(key='CH', directory_name=directory)133 print('CH done ...')134 self.generate_script(key='FR', directory_name=directory)135 print('FR done ...')136 self.generate_script(key='GR', directory_name=directory)137 print('GR done ...')138 self.generate_script(key='IB', directory_name=directory)139 print('IB done ...')140 self.generate_script(key='NEU', directory_name=directory)141 print('NEU done ...')142 self.generate_script(key='SEE', directory_name=directory)143 print('SEE done ...')144 self.generate_script(key='TR', directory_name=directory)145 print('TR done ...')146 self.generate_script(key='UK', directory_name=directory)147 print('UK done ...')148 print()149 print('... Complete')150 def besc(self):151 print('Generating script for BESC ...')152 self.generate_script(key='BESC', directory_name='BESC')153 print('... Done')154 def ch(self):155 print('Generating script for CH ...')156 self.generate_script(key='CH', directory_name='CH')157 print('... Done')158 def fr(self):159 print('Generating script for FR ...')160 self.generate_script(key='FR', directory_name='FR')161 print('... Done')162 def gr(self):163 print('Generating script for GR ...')164 self.generate_script(key='GR', directory_name='GR')165 print('... Done')166 def ib(self):167 print('Generating script for IB ...')168 self.generate_script(key='IB', directory_name='IB')169 print('... Done')170 def neu(self):171 print('Generating script for NEU ...')172 self.generate_script(key='NEU', directory_name='NEU')173 print('... Done')174 def see(self):175 print('Generating script for SEE ...')176 self.generate_script(key='SEE', directory_name='SEE')177 print('... Done')178 def tr(self):179 print('Generating script for TR ...')180 self.generate_script(key='TR', directory_name='TR')181 print('... Done')182 def uk(self):183 print('Generating script for UK ...')184 self.generate_script(key='UK', directory_name='UK')185 print('... Done')186 def uae(self):187 print('Generating script for UAE ...')188 self.generate_script(key='UAE', directory_name='UAE')189 print('... Done')190 191 def ksa(self):192 print('Generating script for KSA ...')193 self.generate_script(key='KSA', directory_name='KSA')194 print('... Done')195 def ind(self):196 print('Generating script for IN ...')197 self.generate_script(key='IND', directory_name='IND')198 print('... Done')199 def do_command(self, command):200 command_method = getattr(self, command.method.__name__)201 if command_method:...

Full Screen

Full Screen

mixins.py

Source: mixins.py Github

copy

Full Screen

...46 print('unable to delete {}'.format(name))47 super(ScriptTearDown, self).tearDown()48class ScriptFactoryMixin(ScriptTearDown, object):49 def setUp(self):50 self.translate_script = factories.generate_script(os.path.join(config.WOOEY_TEST_SCRIPTS, 'translate.py'))51 self.choice_script = factories.generate_script(os.path.join(config.WOOEY_TEST_SCRIPTS, 'choices.py'))52 self.without_args = factories.generate_script(os.path.join(config.WOOEY_TEST_SCRIPTS, 'without_args.py'))53 self.subparser_script = factories.generate_script(os.path.join(config.WOOEY_TEST_SCRIPTS, 'subparser_script.py'))54 self.version1_script = factories.generate_script(55 os.path.join(config.WOOEY_TEST_SCRIPTS, 'versioned_script', 'v1.py'),56 script_name='version_test',57 )58 self.version2_script = factories.generate_script(59 os.path.join(config.WOOEY_TEST_SCRIPTS, 'versioned_script', 'v2.py'),60 script_name='version_test',61 )62 super(ScriptFactoryMixin, self).setUp()63class FileMixin(object):64 def setUp(self):65 self.storage = utils.get_storage(local=not wooey_settings.WOOEY_EPHEMERAL_FILES)66 self.filename_func = lambda x: os.path.join(wooey_settings.WOOEY_SCRIPT_DIR, x)67 super(FileMixin, self).setUp()68 def get_any_file(self):69 script = os.path.join(config.WOOEY_TEST_SCRIPTS, 'command_order.py')...

Full Screen

Full Screen

test_generate_script.py

Source: test_generate_script.py Github

copy

Full Screen

1import pytest2def test_generate_script_no_blocks(visualizer):3 result = visualizer.generate_script("fakeid", list())4 assert result == False5def test_generate_script_no_blocks_text(visualizer):6 result = visualizer.generate_script("fakeid", list(), text=True)7 assert result == False8def test_generate_script_nonexistent(visualizer, full_sb3):9 result = visualizer.generate_script("fakeid", full_sb3["targets"][0]["blocks"])10 assert result == False11def test_generate_script_nonexistent_text(visualizer, full_sb3):12 result = visualizer.generate_script("fakeid", full_sb3["targets"][0]["blocks"], text=True)13 assert result == False14def test_generate_script_exists(parser, visualizer, full_sb3):15 target, _ = parser.get_target("q3cBGj=%#c^E;eayaZs6", full_sb3)16 result = visualizer.generate_script("q3cBGj=%#c^E;eayaZs6", target["blocks"])17 assert result == {'label': 'play sound (Sound! v) until done'}18def test_generate_script_exists_text(parser, visualizer, full_sb3):19 target, _ = parser.get_target("q3cBGj=%#c^E;eayaZs6", full_sb3)20 result = visualizer.generate_script("q3cBGj=%#c^E;eayaZs6", target["blocks"], text=True)21 22 assert result == "play sound (Sound! v) until done\n\n"23 24def test_generate_script_exists_limit(parser, visualizer, full_sb3):25 target, _ = parser.get_target("t0gCI_RcP^f%JiDTILyU", full_sb3)26 surrounding = parser.get_surrounding_blocks("t0gCI_RcP^f%JiDTILyU", full_sb3)27 result = visualizer.generate_script(surrounding[0], target["blocks"], surrounding)28 29 assert result == {'label': 'define test_function', 'next': {'label': 'ask [Question] and wait', 'next': {'label': 'if <(answer) > [50]> then', 'substack': {'label': 'set [test_variable v] to (pick random (1) to (10))', 'next': {'label': 'play sound (Sound! v) until done'}}}}}30def test_generate_script_starts_with_input(parser, visualizer, full_sb3):31 """Should fail since we are forcing scratch-to-blocks to use an INPUT to start."""32 target, _ = parser.get_target("LFsgr8N^R^kVy-c66YJ8", full_sb3)33 with pytest.raises(Exception):34 surrounding = parser.get_surrounding_blocks("LFsgr8N^R^kVy-c66YJ8", full_sb3, 2)35 result = visualizer.generate_script(surrounding[0], target["blocks"], surrounding, find_block=False)36def test_generate_script_nostart_with_input(parser, visualizer, full_sb3):37 """Should succeed since we're letting scratch-to-blocks find the closest BLOCK it can."""38 target, _ = parser.get_target("LFsgr8N^R^kVy-c66YJ8", full_sb3)39 surrounding = parser.get_surrounding_blocks("LFsgr8N^R^kVy-c66YJ8", full_sb3, 2)...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Putting Together a Testing Team

As part of one of my consulting efforts, I worked with a mid-sized company that was looking to move toward a more agile manner of developing software. As with any shift in work style, there is some bewilderment and, for some, considerable anxiety. People are being challenged to leave their comfort zones and embrace a continuously changing, dynamic working environment. And, dare I say it, testing may be the most ‘disturbed’ of the software roles in agile development.

QA Innovation &#8211; Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

What is Selenium Grid &#038; Advantages of Selenium Grid

Manual cross browser testing is neither efficient nor scalable as it will take ages to test on all permutations & combinations of browsers, operating systems, and their versions. Like every developer, I have also gone through that ‘I can do it all phase’. But if you are stuck validating your code changes over hundreds of browsers and OS combinations then your release window is going to look even shorter than it already is. This is why automated browser testing can be pivotal for modern-day release cycles as it speeds up the entire process of cross browser compatibility.

QA&#8217;s and Unit Testing &#8211; Can QA Create Effective Unit Tests

Unit testing is typically software testing within the developer domain. As the QA role expands in DevOps, QAOps, DesignOps, or within an Agile team, QA testers often find themselves creating unit tests. QA testers may create unit tests within the code using a specified unit testing tool, or independently using a variety of methods.

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 ATX 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