Best Python code snippet using avocado_python
__init__.py
Source:__init__.py
...35 homepage = metadata_dict["project_url"][0].split(",", 1)[1].strip()36 spdx_package.homepage = homepage37 spdx_package.summary = metadata.summary38 spdx_package.description = metadata_dict.get("description")39 license = License.from_identifier(metadata.license)40 spdx_package.conc_lics = license41 spdx_package.license_declared = license42 return spdx_package43def convert_wheel(filename: str) -> Document:44 whl = Wheel(filename=filename)45 metadata: Metadata = whl.metadata46 spdx_package = convert_metadata(metadata, filename)47 spdx_document = Document(48 data_license=License.from_identifier("MIT"),49 package=spdx_package,50 version=Version(2, 2),51 name=metadata.name,52 )53 spdx_document.creation_info.created = datetime.now()54 return spdx_document55def convert_site_packages() -> Document:56 dist_path = DistributionPath()57 dists = dist_path.get_distributions()58 spdx_packages = [convert_metadata(dist.metadata) for dist in dists]59 spdx_document = Document(60 data_license=License.from_identifier("MIT"),61 version=Version(2, 2),62 name="site-packages",63 )64 spdx_document.packages.extend(spdx_packages)65 spdx_document.creation_info.created = datetime.now()66 return spdx_document67def main() -> None:68 parser = argparse.ArgumentParser()69 parser.add_argument("--wheel")70 args = parser.parse_args()71 if args.wheel:72 spdx = convert_wheel(args.wheel)73 else:74 spdx = convert_site_packages()...
post_transcript_section_data.py
Source:post_transcript_section_data.py
1"""2Post Transcript Section Data3This script takes a csv of 'Student ID', 'Section ID', and identifier values4and POSTs the values to a transcript identifier at the section level. The5'from_identifier' is the column/identifier on the csv, the 'post_to_identifer'6is the identifier on the transcript to post the values.7Requires: CSV with 'Student ID', 'Section ID', and identifier values columns8Usage: ./post_transcript_section_data.py {schoolcode} {from_identifier}9 {post_to_identifer} {filename}10Returns: nothing11"""12import qs13import sys14def main():15 qs.logger.config(__file__)16 schoolcode = sys.argv[1]17 from_identifier = sys.argv[2]18 to_identifier = sys.argv[3]19 filename = sys.argv[4]20 q = qs.API(schoolcode)21 csv_section_values = qs.CSV(filename)22 sections = dict()23 empty_sections = list()24 if 'Student ID' not in csv_section_values.cols:25 raise ValueError("'Student ID' column required")26 elif 'Section ID' not in csv_section_values.cols:27 raise ValueError("'Section ID' column required")28 elif from_identifier not in csv_section_values.cols:29 raise ValueError("Identifier '{}'column is required" .format(from_identifier))30 qs.logger.info("Retrieving section information and identifier values...", cc_print=True)31 for section in qs.bar(csv_section_values):32 student_id = section['Student ID']33 section_id = section['Section ID']34 identifier_values = section[from_identifier]35 if identifier_values is not None:36 if student_id not in sections:37 sections[student_id] = dict()38 sections[student_id][section_id] = {'values': {to_identifier: identifier_values}}39 else:40 if 'Full Name' in csv_section_values.cols and 'Section Name' in csv_section_values.cols:41 student_name = section['Student Name']42 section_name = section['Section Name']43 empty_sections.append({student_id: section_id, student_name: section_name})44 else:45 empty_sections.append({student_id: section_id})46 qs.logger.info("POSTing data to transcripts' sections...", cc_print=True)47 for student in qs.bar(sections):48 student_id = student49 transcript_data = sections[student]50 q.post_transcript_section_level(student_id, transcript_data)51if __name__ == '__main__':...
DB.py
Source:DB.py
1import sqlite32class DB:3 def __init__(self, db_file):4 self.db = sqlite3.connect(db_file)5 self.init_db()6 self.db.row_factory = sqlite3.Row7 def init_db(self):8 c = self.db.cursor()9 version = self._get_version()10 if version < 1:11 c.execute('create table if not exists files (filename text, uploaded int)')12 self._set_version(1)13 version = 114 if version < 2:15 c.execute('alter table files rename to files_old;')16 c.execute('create table files (filename text, uploaded int, primary key (`filename`)) without rowid;')17 c.execute('insert into files select * from files_old;')18 c.execute('drop table files_old;')19 self._set_version(2)20 if version < 3:21 c.execute('create table archive_identifier_aliases (from_identifier text, identifier text, primary key (`from_identifier`)) without rowid;')22 self._set_version(3)23 self.db.commit()24 def _get_version(self):25 return self.db.cursor().execute('pragma user_version').fetchone()[0]26 def _set_version(self, version):27 self.db.cursor().execute('pragma user_version='+str(version))28 def add_file(self, filename):29 c = self.db.cursor()30 c.execute('insert into files (filename, uploaded) values (?, 1)',31 (filename,))32 self.db.commit()33 def add_item_identifier(self, identifier):34 c = self.db.cursor()35 c.execute('insert into archive_identifier_aliases (from_identifier, identifier) values (?, ?)',36 (identifier.lower(), identifier))37 self.db.commit()38 def get_item_identifier(self, identifier):39 c = self.db.cursor()40 c.execute('select identifier from archive_identifier_aliases where from_identifier = ?', (identifier.lower(),))41 row = c.fetchone()42 if row is not None:43 return row['identifier']44 else:45 self.add_item_identifier(identifier)46 return self.get_item_identifier(identifier)47 def exists(self, filename):48 c = self.db.cursor()49 c.execute('select uploaded from files where filename = ?', (filename,))...
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!!