def run_test7(): ''' Test #7 checks the operation of generating reference list labels. ''' ## Although three of these files were copied from "test1", it is a bad idea to use the "test1.*" files here because ## any changes to test1 would then require changes to the test7_target.bbl as well. bblfile = './test/test7.bbl' bstfile = './test/test7.bst' auxfile = './test/test7.aux' target_bblfile = './test/test7_target.bbl' ## The default locale will be US english. Ironically, the locale argument needs to use an ASCII string, and since ## the default string encoding here is Unicode, we have to re-encode it manually. Later below, we will try some ## other locale settings. if (os.name == 'posix'): thislocale = locale.setlocale(locale.LC_ALL,'en_US.UTF8'.encode('ascii','replace')) elif (os.name == 'nt'): thislocale = locale.setlocale(locale.LC_ALL,'usa_usa'.encode('ascii','replace')) ## Need to make a list of all the citation label options we want to try. Skip "citenum" since that is the default, ## and so has been tested already. citelabels = ['<citekey>', '[<authorlist.0.last>|<editorlist.0.last>|]-<year>', '<citealpha>', '[<authorlist.0.last>|<editorlist.0.last>|], <year>', '[<authorlist.0.last>|<editorlist.0.last>|] (<year>)', '(<citealnum>)'] print('\n' + '='*75) print('Running Bibulous Test #7') filehandle = open(bstfile, 'r') lines = filehandle.readlines() filehandle.close() for i in range(len(citelabels)): citelabel = citelabels[i] ## First go into the BST file and rewrite the "citelabel" line to be the current sortkey template. filehandle = open(bstfile, 'w') for line in lines: if line.startswith('citelabel = '): filehandle.write('citelabel = ' + citelabel + '\n') else: filehandle.write(line) filehandle.close() bibobj = Bibdata(auxfile, disable=[9], silent=(i>0)) bibobj.locale = thislocale bibobj.bibdata['preamble'] = '\n\n%% SETTING CITELABEL = ' + citelabel #bibobj.debug = True ## turn on debugging for citekey printing print('Setting citation_label = ' + citelabel) write_preamble = (citelabel == citelabels[0]) write_postamble = (citelabel == citelabels[-1]) if not write_preamble: filehandle = open(bblfile, 'a') filehandle.write('\n\n%% SETTING SETTING CITELABEL = ' + citelabel + '\n') filehandle.close() bibobj.write_bblfile(write_preamble=write_preamble, write_postamble=write_postamble) return(bblfile, target_bblfile)
def run_test4(): ''' Test #4 checks the operation of generating citation keys. ''' ## Although three of these files were copied from "test1", it is a bad idea to use the "test1.*" files here because ## any changes to test1 would then require changes to the test4_target.bbl as well. bblfile = './test/test4.bbl' bstfile = './test/test4.bst' auxfile = './test/test4.aux' target_bblfile = './test/test4_target.bbl' ## The default locale will be US english. Ironically, the locale argument needs to use an ASCII string, and since ## the default string encoding here is Unicode, we have to re-encode it manually. Later below, we will try some ## other locale settings. if (os.name == 'posix'): thislocale = locale.setlocale(locale.LC_ALL,'en_US.UTF8'.encode('ascii','replace')) elif (os.name == 'nt'): thislocale = locale.setlocale(locale.LC_ALL,'usa_usa'.encode('ascii','replace')) ## Need to make a list of all the citation sort options we want to try. Skip "citenum" since that is the default, ## and so has been tested already. Note: In the "uniquify" example below, the .upper() operator is needed to force the ## code to see 'b' and 'B' as being the same (and thus need a unique ending) when case-indep. sorting is being used. presortkeys = ['<citekey>', '[<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sortyear.zfill(4)>|<year.zfill(4)>|][<sorttitle>|<title>]<citekey>', '[<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sorttitle>|<title>][<sortyear.zfill(4)>|<year.zfill(4)>|]<citekey>', '[<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sortyear.zfill(4)>|<year.zfill(4)>|]<volume>[<sorttitle>|<title>]<citekey>', '[<alphalabel>][<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sortyear.zfill(4)>|<year.zfill(4)>|][<sorttitle>|<title>]<citekey>', '[<alphalabel>][<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sortyear.zfill(4)>|<year.zfill(4)>|]<volume>[<sorttitle>|<title>]<citekey>', '[<sortyear.zfill(4)>|<year.zfill(4)>][<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sorttitle>|<title>]<citekey>', '[<sortyear.zfill(4)>|<year.zfill(4)>][<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sorttitle>|<title>]<citekey>', #'<author_or_editor.initial().upper().uniquify(num)>', '[<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sortyear.zfill(4)>|<year.zfill(4)>][<sorttitle>|<title>]<citekey>'] sortkeys = ['<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', #'<presortkey.purify().lower().compress()>', '<presortkey.purify().compress()>'] ## do not use .lower() here, in order to test sorting *with* case sensitivity sort_case_options = ['False', 'False', 'False', 'False', 'False', 'False', 'False', 'False', 'True'] #sort_case_options = ['True', 'True', 'True', 'True', 'True', 'True', 'True', 'True', 'True'] sort_order_options = ['Forward', 'Forward', 'Forward', 'Forward', 'Forward', 'Forward', 'Forward', 'Reverse', 'Forward'] print('\n' + '='*75) print('Running Bibulous Test #4') filehandle = open(bstfile, 'r') lines = filehandle.readlines() filehandle.close() for i in range(len(sortkeys)): presortkey = presortkeys[i] sortkey = sortkeys[i] sort_case_option = sort_case_options[i] sort_order_option = sort_order_options[i] ## First go into the BST file and rewrite the "sortkey" line to be the current sortkey template. filehandle = open(bstfile, 'w') for line in lines: if line.startswith('presortkey = '): filehandle.write('presortkey = ' + presortkey + '\n') elif line.startswith('sortkey = '): filehandle.write('sortkey = ' + sortkey + '\n') elif line.startswith('sort_case = '): filehandle.write('sort_case = ' + sort_case_option + '\n') elif line.startswith('sort_order = '): filehandle.write('sort_order = ' + sort_order_option + '\n') else: filehandle.write(line) filehandle.close() bibobj = Bibdata(auxfile, disable=[9], silent=(i>0)) bibobj.locale = thislocale bibobj.bibdata['preamble'] = '\n\n%% SETTING PRESORTKEY = ' + presortkey bibobj.bibdata['preamble'] += '\n%% SETTING SORTKEY = ' + sortkey #bibobj.debug = True ## turn on debugging for citekey printing print('Setting PRESORTKEY = ' + presortkey) print('Setting SORTKEY = ' + sortkey) write_preamble = (presortkey == presortkeys[0]) write_postamble = (presortkey == presortkeys[-1]) if not write_preamble: filehandle = open(bblfile, 'a') filehandle.write('\n\n%% SETTING PRESORTKEY = ' + presortkey + '\n') filehandle.write('%% SETTING SORTKEY = ' + sortkey + '\n') #if (sort_case_option == 'True'): filehandle.write('%% SETTING SORT_CASE = True\n') if (sort_order_option == 'Reverse'): filehandle.write('%% SETTING SORT_ORDER = Reverse\n') filehandle.close() bibobj.write_bblfile(write_preamble=write_preamble, write_postamble=write_postamble, bibsize='ZZZ') return(bblfile, target_bblfile)
def run_test4(): ''' Test #4 checks the operation of generating citation keys. ''' ## Although three of these files were copied from "test1", it is a bad idea to use the "test1.*" files here because ## any changes to test1 would then require changes to the test4_target.bbl as well. bblfile = './test/test4.bbl' bstfile = './test/test4.bst' auxfile = './test/test4.aux' target_bblfile = './test/test4_target.bbl' ## The default locale will be US english. Ironically, the locale argument needs to use an ASCII string, and since ## the default string encoding here is Unicode, we have to re-encode it manually. Later below, we will try some ## other locale settings. if (os.name == 'posix'): thislocale = locale.setlocale(locale.LC_ALL,'en_US.UTF8'.encode('ascii','replace')) elif (os.name == 'nt'): thislocale = locale.setlocale(locale.LC_ALL,'usa_usa'.encode('ascii','replace')) ## Need to make a list of all the citation sort options we want to try. Skip "citenum" since that is the default, ## and so has been tested already. Note: In the "uniquify" example below, the .upper() operator is needed to force the ## code to see 'b' and 'B' as being the same (and thus need a unique ending) when case-indep. sorting is being used. presortkeys = ['<citekey>', '[<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sortyear.zfill(4)>|<year.zfill(4)>|][<sorttitle>|<title>]', '[<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sorttitle>|<title>][<sortyear.zfill(4)>|<year.zfill(4)>|]', '[<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sortyear.zfill(4)>|<year.zfill(4)>|]<volume>[<sorttitle>|<title>]', '[<alphalabel>][<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sortyear.zfill(4)>|<year.zfill(4)>|][<sorttitle>|<title>]', '[<alphalabel>][<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sortyear.zfill(4)>|<year.zfill(4)>|]<volume>[<sorttitle>|<title>]', '[<sortyear.zfill(4)>|<year.zfill(4)>][<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sorttitle>|<title>]', '[<sortyear.zfill(4)>|<year.zfill(4)>][<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sorttitle>|<title>]', #'<author_or_editor.initial().upper().uniquify(num)>', '[<sortname>|<authorlist.0.last>|<editorlist.0.last>|][<authorlist.0.first>|<editorlist.0.first>][<sortyear.zfill(4)>|<year.zfill(4)>][<sorttitle>|<title>]'] sortkeys = ['<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', '<presortkey.purify().lower().compress()>', #'<presortkey.purify().lower().compress()>', '<presortkey.purify().compress()>'] ## do not use .lower() here, in order to test sorting *with* case sensitivity sort_case_options = ['False', 'False', 'False', 'False', 'False', 'False', 'False', 'False', 'True'] #sort_case_options = ['True', 'True', 'True', 'True', 'True', 'True', 'True', 'True', 'True'] sort_order_options = ['Forward', 'Forward', 'Forward', 'Forward', 'Forward', 'Forward', 'Forward', 'Reverse', 'Forward'] print('\n' + '='*75) print('Running Bibulous Test #4') filehandle = open(bstfile, 'r') lines = filehandle.readlines() filehandle.close() for i in range(len(sortkeys)): presortkey = presortkeys[i] sortkey = sortkeys[i] sort_case_option = sort_case_options[i] sort_order_option = sort_order_options[i] ## First go into the BST file and rewrite the "sortkey" line to be the current sortkey template. filehandle = open(bstfile, 'w') for line in lines: if line.startswith('presortkey = '): filehandle.write('presortkey = ' + presortkey + '\n') elif line.startswith('sortkey = '): filehandle.write('sortkey = ' + sortkey + '\n') elif line.startswith('sort_case = '): filehandle.write('sort_case = ' + sort_case_option + '\n') elif line.startswith('sort_order = '): filehandle.write('sort_order = ' + sort_order_option + '\n') else: filehandle.write(line) filehandle.close() bibobj = Bibdata(auxfile, disable=[9], silent=(i>0)) bibobj.locale = thislocale bibobj.bibdata['preamble'] = '\n\n%% SETTING PRESORTKEY = ' + presortkey bibobj.bibdata['preamble'] += '\n%% SETTING SORTKEY = ' + sortkey #bibobj.debug = True ## turn on debugging for citekey printing print('Setting PRESORTKEY = ' + presortkey) print('Setting SORTKEY = ' + sortkey) write_preamble = (presortkey == presortkeys[0]) write_postamble = (presortkey == presortkeys[-1]) if not write_preamble: filehandle = open(bblfile, 'a') filehandle.write('\n\n%% SETTING PRESORTKEY = ' + presortkey + '\n') filehandle.write('%% SETTING SORTKEY = ' + sortkey + '\n') #if (sort_case_option == 'True'): filehandle.write('%% SETTING SORT_CASE = True\n') if (sort_order_option == 'Reverse'): filehandle.write('%% SETTING SORT_ORDER = Reverse\n') filehandle.close() bibobj.write_bblfile(write_preamble=write_preamble, write_postamble=write_postamble, bibsize='ZZZ') return(bblfile, target_bblfile)