Best Python code snippet using avocado_python
emailing.py
Source:emailing.py
1import os2import smtplib3import zipfile4import tempfile5from email import encoders6from email.message import Message7from email.mime.base import MIMEBase8from email.mime.multipart import MIMEMultipart 9def send_email(the_files, *, recipients, subject, sender='ian.bell@nist.gov'):10 """11 https://stackoverflow.com/questions/10474650/how-to-send-a-zip-file-as-an-attachment-in-python12 """13 # Create the message14 themsg = MIMEMultipart()15 themsg['Subject'] = subject16 to = ', '.join(recipients)17 themsg['To'] = to18 themsg['From'] = sender19 themsg['Contents'] = "something"20 themsg.preamble = 'I am not using a MIME-aware mail reader.\n'21 for the_file in the_files:22 if the_file is not None:23 ext = os.path.split(the_file)[1].split('.')[1]24 if ext == 'zip':25 msg = MIMEBase('application', 'zip')26 with open(the_file, 'rb') as zf:27 msg.set_payload(zf.read())28 encoders.encode_base64(msg)29 elif ext == 'html':30 msg = MIMEBase('text', 'html')31 with open(the_file) as fp:32 msg.set_payload(fp.read())33 else:34 raise ValueError("Don't know how to attach this file:" + the_file)35 msg.add_header('Content-Disposition', 'attachment', 36 filename=os.path.basename(the_file))37 themsg.attach(msg)38 # Send the email via SMTP39 with smtplib.SMTP('smtp.nist.gov') as smtp:40 smtp.ehlo(); # print(smtp.ehlo_resp)41 smtp.send_message(themsg)42if __name__=='__main__':43 files = ['test_build_run.html', 'test.zip', 'gcov_build_run.html', 'gcov.zip']...
test_build.py
Source:test_build.py
...12 out, err = r.communicate()13 self.assertEqual(out, "")14 self.assertRegex(err, "(too few arguments|arguments are required)")15 self.assertNotEqual(r.returncode, 0)16 def test_build_run(self):17 """Test build module run"""18 def assert_fitting_ok(param, chimera):19 self.assertEqual(param, "params")20 self.assertEqual(chimera, "chimera.out")21 old = IMP.cnmultifit.do_all_fitting22 try:23 IMP.cnmultifit.do_all_fitting = assert_fitting_ok24 self.run_python_module(build, ['--chimera', 'chimera.out',25 'params'])26 finally:27 IMP.cnmultifit.do_all_fitting = old28if __name__ == '__main__':...
test_textattack.py
Source:test_textattack.py
...11 cfstate._init_state()12 cfstate.load_framework("textattack")13 cfstate.load_target(target)14 return cfstate15 def test_build_run(self, cfstate_state, target):16 scan_id = set_id()17 cfattack_id = cfstate_state.build_new_attack(target, "DeepWordBugGao2018", scan_id)18 assert cfattack_id is not None19 attack_complete = cfstate_state.run_attack(target, cfattack_id)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!