def test_is_not_directory(self): # Arrange text = "abc" # Act it_is_not = _util.isDirectory(text) # Assert self.assertFalse(it_is_not)
def test_is_directory(self): # Arrange directory = "Tests" # Act it_is = _util.isDirectory(directory) # Assert self.assertTrue(it_is)
def test_is_not_directory(): # Arrange text = "abc" # Act it_is_not = _util.isDirectory(text) # Assert assert not it_is_not
def test_is_directory(): # Arrange directory = "Tests" # Act it_is = _util.isDirectory(directory) # Assert assert it_is
def load_path(filename): "Load a font file, searching along the Python path." for dir in sys.path: if isDirectory(dir): if not isinstance(filename, "utf-8"): if bytes is str: filename = filename.encode("utf-8") else: filename = filename.decode("utf-8") try: return load(os.path.join(dir, filename)) except IOError: pass raise IOError("cannot find font file")
def load_path(filename): """ Load font file. Same as :py:func:`~PIL.ImageFont.load`, but searches for a bitmap font along the Python path. :param filename: Name of font file. :return: A font object. :exception IOError: If the file could not be read. """ for dir in sys.path: if isDirectory(dir): if not isinstance(filename, str): if bytes is str: filename = filename.encode("utf-8") else: filename = filename.decode("utf-8") try: return load(os.path.join(dir, filename)) except IOError: pass raise IOError("cannot find font file")
def load_path(filename): """ Load font file. Same as :py:func:`~PIL.ImageFont.load`, but searches for a bitmap font along the Python path. :param filename: Name of font file. :return: A font object. :exception IOError: If the file could not be read. """ for directory in sys.path: if isDirectory(directory): if not isinstance(filename, str): if bytes is str: filename = filename.encode("utf-8") else: filename = filename.decode("utf-8") try: return load(os.path.join(directory, filename)) except IOError: pass raise IOError("cannot find font file")
def standardization(standardization_input, standardization_output): #df_=df.loc[df['unzip'] == 'complete'] work_dirs = [ f for f in os.listdir(standardization_input) if isDirectory(os.path.join(standardization_input, f)) ] for work_dir in work_dirs: work_dir_output = os.path.join(standardization_output, work_dir) if not os.path.exists(work_dir_output): os.makedirs(work_dir_output) update_folder = os.path.join(standardization_input, work_dir) folders = [ f for f in os.listdir(update_folder) if isDirectory(os.path.join(update_folder, f)) ] for sub_folder in folders: output_folder = os.path.join(work_dir_output, sub_folder) if not os.path.exists(output_folder): os.makedirs(output_folder) sub_folder = os.path.join(update_folder, sub_folder) files = [ f for f in os.listdir(sub_folder) if os.path.isfile(os.path.join(sub_folder, f)) ] for file_name in files: if (file_name.endswith(".xml")): file_path = os.path.join(sub_folder, file_name) with open(file_path, 'r') as xml_file: try: file_name = file_name[:-4] docXml = ET.parse(xml_file) print("Processing pmid:" + file_path) root = docXml.getroot() xml_string = ET.tostring(root, encoding='utf-8', method='xml') o = xmltodict.parse(xml_string, encoding='utf-8') jsonString = json.dumps(o, indent=4) json_file = open( output_folder + "/" + file_name + ".json", 'w') json_file.write(jsonString) json_file.flush() json_file.close() txt = ET.tostring(root, encoding='utf-8', method='text') txt_file = open( output_folder + "/" + file_name + ".txt", 'w') txt_file.write(txt) txt_file.flush() txt_file.close() ''' df.at[index,'name']=pmc_id df.at[index,'date']=str(datetime.now().date()) df.at[index,'time']=str(datetime.now().time()) df.at[index,'standardization']="complete" df.at[index,'txt_path']=file_path df.at[index,'json_path']=file_path df.to_csv(result_file) ''' except Exception as inst: print "Error Generando el JSON PMID " + file print inst x = inst.args print x