Esempio n. 1
0
def run_test2():
    '''
    Test #2 loads a number of large .bib database files to put the BibTeX parser and the BBL file writer through a
    comprehensive set of conditions. Every entry in the BIB files is written to the output BBL file to test as much
    of the processing chain as possible.

    Rather than checking the output against a target file, this test really just makes sure that no exceptions are
    emitted when processing the entire database through the full chain of functions.
    '''

    auxfile = './test/test2.aux'

    print('\n' + '='*75)
    print('Running Bibulous Test #2')

    ## If no excepts are raised when reading the BIB file or writing the BBL file, then the test passes.
    try:
        bibobj = Bibdata(auxfile, disable=[4,6,9,11,18,20,21,25,32,33])
        bibobj.write_bblfile()
        result = True
        print('TEST #2 PASSED')
    except getopt.GetoptError as err:
        print('Error encountered: ' + err)
        result = False
        print('TEST #2 FAILED.')

    return(result)
Esempio n. 2
0
def run_test2():
    '''
    Test #2 loads a number of large .bib database files to put the BibTeX parser and the BBL file writer through a
    comprehensive set of conditions. Every entry in the BIB files is written to the output BBL file to test as much
    of the processing chain as possible.

    Rather than checking the output against a target file, this test really just makes sure that no exceptions are
    emitted when processing the entire database through the full chain of functions.
    '''

    auxfile = './test/test2.aux'

    print('\n' + '='*75)
    print('Running Bibulous Test #2')

    ## If no excepts are raised when reading the BIB file or writing the BBL file, then the test passes.
    try:
        bibobj = Bibdata(auxfile, disable=[4,6,9,11,18,20,21,25,32,33])
        bibobj.write_bblfile()
        result = True
        print('TEST #2 PASSED')
    except getopt.GetoptError as err:
        print('Error encountered: ' + err)
        result = False
        print('TEST #2 FAILED.')

    return(result)
Esempio n. 3
0
def run_test9():
    '''
    Test #9 is a platform for running conditions in which the entire database needs to be re-read with each test.
    '''

    auxfiles = [
        './test/test9_case_sensitive_fieldnames.aux',
        './test/test9_italian_name_separator.aux'
    ]
    bblfile = './test/test9.bbl'
    target_bblfile = './test/test9_target.bbl'

    print('\n' + '=' * 75)
    print('Running Bibulous Test #9')

    for auxfile in auxfiles:
        bibobj = Bibdata(auxfile, disable=[9], silent=(auxfile != auxfiles[0]))
        bibobj.filedict['bbl'] = bblfile
        write_preamble = (auxfile == auxfiles[0])
        write_postamble = (auxfile == auxfiles[-1])
        bibobj.write_bblfile(write_preamble=write_preamble,
                             write_postamble=write_postamble)
        print('')

    return (bblfile, target_bblfile)
Esempio n. 4
0
def run_test1():
    '''
    Test #1 consists of a suite of single tests of options and features that are valid with the default template file.
    '''

    bblfile = './test/test1.bbl'
    auxfile = './test/test1.aux'
    target_bblfile = './test/test1_target.bbl'

    print('\n' + '='*75)
    print('Running Bibulous Test #1')

    bibobj = Bibdata(auxfile, disable=[9,17,28,29])
    bibobj.write_bblfile(write_preamble=True, write_postamble=True, bibsize='ZZ')

    return(bblfile, target_bblfile)
Esempio n. 5
0
def run_test8():
    '''
    Test #8 tests Bibulous' ability to generate glossaries, symbol lists, and acronym lists.
    '''

    bblfile = './test/test8.bbl'
    auxfile = './test/test8.aux'
    target_bblfile = './test/test8_target.bbl'

    print('\n' + '='*75)
    print('Running Bibulous Test #8')

    bibobj = Bibdata(auxfile, debug=False)
    bibobj.write_bblfile()

    return(bblfile, target_bblfile)
Esempio n. 6
0
def run_test5():
    '''
    Test #5 flexes the Python API.
    '''

    auxfile = './test/test5.aux'
    bblfile = './test/test5.bbl'
    targetfile = './test/test5_target.bbl'

    print('\n' + '='*75)
    print('Running Bibulous Test #5')

    bibobj = Bibdata(auxfile, disable=[9], debug=False)
    bibobj.write_bblfile(write_preamble=True, write_postamble=True)

    return(bblfile, targetfile)
Esempio n. 7
0
def run_test1():
    '''
    Test #1 consists of a suite of single tests of options and features that are valid with the default template file.
    '''

    bblfile = './test/test1.bbl'
    auxfile = './test/test1.aux'
    target_bblfile = './test/test1_target.bbl'

    print('\n' + '='*75)
    print('Running Bibulous Test #1')

    bibobj = Bibdata(auxfile, disable=[9,17,28,29])
    bibobj.write_bblfile(write_preamble=True, write_postamble=True, bibsize='ZZ')

    return(bblfile, target_bblfile)
Esempio n. 8
0
def run_test8():
    '''
    Test #8 tests Bibulous' ability to generate glossaries, symbol lists, and acronym lists.
    '''

    bblfile = './test/test8.bbl'
    auxfile = './test/test8.aux'
    target_bblfile = './test/test8_target.bbl'

    print('\n' + '='*75)
    print('Running Bibulous Test #8')

    bibobj = Bibdata(auxfile, debug=False)
    bibobj.write_bblfile()

    return(bblfile, target_bblfile)
Esempio n. 9
0
def run_test5():
    '''
    Test #5 flexes the Python API.
    '''

    auxfile = './test/test5.aux'
    bblfile = './test/test5.bbl'
    targetfile = './test/test5_target.bbl'

    print('\n' + '='*75)
    print('Running Bibulous Test #5')

    bibobj = Bibdata(auxfile, disable=[9], debug=False)
    bibobj.write_bblfile(write_preamble=True, write_postamble=True)

    return(bblfile, targetfile)
Esempio n. 10
0
def run_test10():
    '''
    Test #10 checks Bibulous' ability to sort numbers correctly (i.e. "human" sorting, so that "10" goes after, not
    before, "2").
    '''

    bblfile = './test/test10_humansort.bbl'
    auxfile = './test/test10_humansort.aux'
    target_bblfile = './test/test10_humansort_target.bbl'

    print('\n' + '='*75)
    print('Running Bibulous Test #10')

    bibobj = Bibdata(auxfile, debug=False)
    bibobj.write_bblfile()

    return(bblfile, target_bblfile)
Esempio n. 11
0
def run_test10():
    '''
    Test #10 checks Bibulous' ability to sort numbers correctly (i.e. "human" sorting, so that "10" goes after, not
    before, "2").
    '''

    bblfile = './test/test10_humansort.bbl'
    auxfile = './test/test10_humansort.aux'
    target_bblfile = './test/test10_humansort_target.bbl'

    print('\n' + '=' * 75)
    print('Running Bibulous Test #10')

    bibobj = Bibdata(auxfile, debug=False)
    bibobj.write_bblfile()

    return (bblfile, target_bblfile)
Esempio n. 12
0
def run_test9():
    '''
    Test #9 is a platform for running conditions in which the entire database needs to be re-read with each test.
    '''

    auxfiles = ['./test/test9_case_sensitive_fieldnames.aux',
                './test/test9_italian_name_separator.aux']
    bblfile = './test/test9.bbl'
    target_bblfile = './test/test9_target.bbl'

    print('\n' + '='*75)
    print('Running Bibulous Test #9')

    for auxfile in auxfiles:
        bibobj = Bibdata(auxfile, disable=[9], silent=(auxfile != auxfiles[0]))
        bibobj.filedict['bbl'] = bblfile
        write_preamble = (auxfile == auxfiles[0])
        write_postamble = (auxfile == auxfiles[-1])
        bibobj.write_bblfile(write_preamble=write_preamble, write_postamble=write_postamble)
        print('')

    return(bblfile, target_bblfile)
Esempio n. 13
0
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)
Esempio n. 14
0
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)
Esempio n. 15
0
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)
Esempio n. 16
0
def run_test1():
    auxfile = './test/test1.aux'
    bibobj = Bibdata(auxfile, disable=[9,17])
    bibobj.write_bblfile(write_preamble=True, write_postamble=True, bibsize='ZZ')
    return
Esempio n. 17
0
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)