Best Python code snippet using lisa_python
content.py
Source:content.py
...17 @abstractmethod18 def get_text(self, key, prefix=""):19 pass20 @classmethod21 def append_prefix(cls, base_prefix, prefix):22 sep = ""23 if len(base_prefix) > 0 and len(prefix) > 0 and not base_prefix.endswith("/") and not prefix.startswith("/"):24 sep = "/"25 return base_prefix + sep + prefix26class FileSystemContentHandler(ContentHandler, ABC):27 def __init__(28 self,29 base_folder='.',30 encoding='utf-8'31 ):32 self.base_folder = base_folder33 self.encoding = encoding34 super().__init__()35 def list(self, prefix=""):36 path = Path(self.base_folder + "/" + prefix)37 path.mkdir(parents=True, exist_ok=True)38 return [f for f in listdir(path) if isfile(path / f)]39 def save_text(self, key, text, prefix=""):40 path = Path(self.base_folder + "/" + prefix)41 path.mkdir(parents=True, exist_ok=True)42 full_path = path / key43 with full_path.open("w", encoding=self.encoding) as f:44 f.write(text)45 def get_text(self, key, prefix=""):46 full_path = self.base_folder + "/" + prefix + "/" + key47 text = Path(full_path).read_text(encoding=self.encoding)48 return text49class AwsS3ContentHandler(ContentHandler, ABC):50 def __init__(51 self,52 bucket=None,53 base_prefix='',54 encoding='utf-8'55 ):56 assert(bucket is not None)57 self.bucket = bucket58 self.base_prefix = base_prefix59 self.encoding = encoding60 self.client = boto3.client('s3')61 super().__init__()62 def list(self, prefix=""):63 result = []64 full_prefix = self.append_prefix(self.base_prefix, prefix)65 response = self.client.list_objects_v2(Bucket=self.bucket, Prefix=full_prefix)66 replace = ""67 if len(full_prefix) > 0 and not full_prefix.endswith("/"):68 replace = full_prefix + "/"69 while True and response.get("Contents"):70 contents = response["Contents"]71 result.extend([i["Key"].replace(replace, "") for i in contents])72 if not response["IsTruncated"]:73 break74 response = self.client.list_objects_v2(75 Bucket=self.bucket,76 ContinuationToken=response['NextContinuationToken'],77 Prefix=full_prefix78 )79 return result80 def save_text(self, key, text, prefix=""):81 full_prefix = self.append_prefix(self.base_prefix, prefix)82 full_key = self.append_prefix(full_prefix, key)83 self.client.put_object(84 Bucket=self.bucket,85 Key=full_key,86 ContentEncoding=self.encoding,87 Body=text.encode(self.encoding)88 )89 def get_text(self, key, prefix=""):90 full_prefix = self.append_prefix(self.base_prefix, prefix)91 full_key = self.append_prefix(full_prefix, key)92 response = self.client.get_object(Bucket=self.bucket, Key=full_key)93 text = response['Body'].read().decode(response['ContentEncoding'])...
aerof_cls.py
Source:aerof_cls.py
...29 bounCond.Inlet.Alpha = self.desc[3]30 bounCond.Inlet.Beta = self.desc[4]31 if desc_ext[0] is not None: prob.MultipleSolutions = desc_ext[0]32 prefix = 'aerof'33 def append_prefix(s): return "{0:s}.{1:s}".format(prefix, s)34 outp.Postpro.LiftandDrag = append_prefix('liftdrag')35 outp.Postpro.Pressure = append_prefix('pressure')36 outp.Restart.Solution = append_prefix('sol')37 outp.Restart.Restart = append_prefix('rst')38 mach = self.desc[2]39 time.CflMax = np.min([1.0e4,np.max([100.0,100.0e1*(mach-0.3)/0.4 +40 1.0e4*(0.7-mach)/0.4])])41 fname = append_prefix('input')42 log = append_prefix('log')43 self.infile = AerofInputFile(fname, [prob, inpu, outp, surf, equa,44 bounCond, spac, time], log)45class AerofRom(Aerof):46 def __init__(**kwargs):47 super(AerofRom, self).__init__(**kwargs)48 def create_input_file(self, p, desc_ext, db=None):49 # Use p, desc_ext, self.desc to create input file50 self.infile = None51class AerofGnat(Aerof):52 def __init__(**kwargs):53 super(AerofGnat, self).__init__(**kwargs)54 def create_input_file(self, p, desc_ext, db=None):55 # Use p, desc_ext, self.desc to create input file56 self.infile = None
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!!