def test__using_with__no_params(self): with Temp_File() as temp: assert Files.file_extension(temp.file_path) == '.tmp' assert Files.exists (temp.file_path) assert Files.contents(temp.file_path) == '...' assert Files.not_exists(temp.file_path) with Temp_File('abc','txt') as temp: assert Files.file_extension(temp.file_path) == '.txt' assert Files.exists (temp.file_path) assert Files.contents(temp.file_path) == 'abc' assert Files.not_exists(temp.file_path)
def run(event, context): load_dependency('pydot') channel = event.get('channel') data = event.get('dot') #slack_message("in dot to svg: {0}".format(event), [], channel) log_to_elk("in dot to svg: {0}".format(event)) import dot_parser try: (fd, tmp_file) = tempfile.mkstemp('dot)') dot_static = '/tmp/lambdas-dependencies/pydot/dot_static' Process.run("chmod", ['+x', dot_static]) data = data.replace('<', '<').replace('>','>') # this solved a really nasty bug caused by the fact that Slack will html encode the < and > # graph = pydot.graph_from_dot_data(data).pop() # <from pydot> use code below (instead of above) to get a better error message from dot parser graphparser = dot_parser.graph_definition() graphparser.parseWithTabs() tokens = graphparser.parseString(data) graph = list(tokens).pop() # </from pydot> graph.write_svg(tmp_file, prog=dot_static) svg_raw = Files.contents(tmp_file) return base64.b64encode(svg_raw.encode()).decode() except Exception as error: slack_message("[dot_to_svg] Error: {0} ".format(error), [], channel) return None
def test_invoke___jira_issues_dot_file(self): dot = Files.contents('../../../data/jira-test.dot') Dev.pprint(dot) params = { "dot": dot , "channel": "DDKUZTK6X"} svg = self.dot_to_svg.update().invoke(params) #how_Img.from_svg_string(svg) Dev.pprint(svg)
def test_upload(self): tmp_folder = Temp_Folder_Code(self.lambda_name) (self.aws_lambda.set_s3_bucket (self.s3_bucket ) .set_s3_key (self.s3_key ) .set_folder_code(tmp_folder.folder )) #self.aws_lambda.upload() #assert tmp_folder.s3_file_exists() is True downloaded_file = self.aws_lambda.s3().file_download(self.s3_bucket, self.s3_key) # download file uploaded assert Files.exists(downloaded_file) unzip_location = tmp_folder.folder + '_unzipped' Files.unzip_file(downloaded_file,unzip_location) # unzip it assert Files.contents(Files.find(unzip_location+'/*').pop()) == tmp_folder.lambda_code # confirm unzipped file's contents self.aws_lambda.s3().file_delete(self.s3_bucket, self.s3_key)
def dockerfile(self): return Files.contents(self.path_docker_file)
def csv_file_raw_data(self, file_name): file_path = self.csv_files().get(file_name) return Files.contents(file_path)
def screenshot_file(self, html_file, img_file=None, clip=None): return self.screenshot_html(Files.contents(html_file), img_file, clip)
def render_file(self, html_file): return self.render_html(Files.contents(html_file))