def step_impl(context, translator, expected):
  expected = expand_scenario_variables(context, expected)
  context.zotero.export_library(
    displayOptions = context.displayOptions,
    translator = translator,
    expected = expected
  )
Beispiel #2
0
def export_library(context,
                   translator='BetterBibTeX JSON',
                   collection=None,
                   expected=None,
                   output=None,
                   displayOption=None,
                   timeout=None,
                   resetCache=False):
    expected = expand_scenario_variables(context, expected)
    displayOptions = {**context.displayOptions}
    if displayOption: displayOptions[displayOption] = True

    start = time.time()
    context.zotero.export_library(displayOptions=displayOptions,
                                  translator=translator,
                                  output=output,
                                  expected=expected,
                                  resetCache=resetCache,
                                  collection=collection)
    runtime = time.time() - start

    if timeout is not None:
        assert (
            runtime < timeout
        ), f'Export runtime of {runtime} exceeded set maximum of {timeout}'
Beispiel #3
0
def step_impl(context, translator, displayOption, expected):
    expected = expand_scenario_variables(context, expected)
    context.zotero.export_library(displayOptions={
        **context.displayOptions, displayOption: True
    },
                                  translator=translator,
                                  expected=expected)
Beispiel #4
0
def step_impl(context, source, db):
    source = expand_scenario_variables(context, source)
    context.imported = source

    with open(os.path.join(ROOT, 'test', 'fixtures', source)) as f:
        data = json.load(f)
        items = data['items']
        #references = sum([ 1 + len(item.get('attachments', [])) + len(item.get('notes', [])) for item in items ])
        references = len(items)

    dbs = os.path.join(ROOT, 'test', 'db', db)
    if not os.path.exists(dbs): os.makedirs(dbs)
    zotero = os.path.join(dbs, 'zotero.sqlite')
    if not os.path.exists(zotero):
        urllib.request.urlretrieve(
            f'https://github.com/retorquere/zotero-better-bibtex/releases/download/test-database/{db}.zotero.sqlite',
            zotero)
    bbt = os.path.join(dbs, 'better-bibtex.sqlite')
    if not os.path.exists(bbt):
        urllib.request.urlretrieve(
            f'https://github.com/retorquere/zotero-better-bibtex/releases/download/test-database/{db}.better-bibtex.sqlite',
            bbt)

    timeout = context.zotero.timeout
    context.zotero.shutdown()
    context.zotero = Zotero(context.config.userdata,
                            db=Munch(zotero=zotero, bbt=bbt))
    context.zotero.timeout = timeout
    assert_that(
        context.zotero.execute(
            'return await Zotero.BetterBibTeX.TestSupport.librarySize()'),
        equal_to(references))

    context.zotero.import_file(context, source, items=False)
def step_impl(context, translator, output, expected):
  expected = expand_scenario_variables(context, expected)
  context.zotero.export_library(
    displayOptions = { **context.displayOptions, 'keepUpdated': True},
    translator = translator,
    output = output,
    expected = expected,
    resetCache = True
  )
Beispiel #6
0
def step_impl(context, translator, output, expected):
    expected = expand_scenario_variables(context, expected)
    context.zotero.export_library(displayOptions={
        **context.displayOptions, 'keepUpdated': True
    },
                                  translator=translator,
                                  output=output,
                                  expected=expected,
                                  resetCache=True)
Beispiel #7
0
def step_impl(context, expected, found):
  expected = expand_scenario_variables(context, expected)
  if expected[0] != '/': expected = os.path.join(ROOT, 'test/fixtures', expected)
  with open(expected) as f:
    expected = f.read()

  if found[0] != '/': found = os.path.join(ROOT, 'test/fixtures', found)
  with open(found) as f:
    found = f.read()

  assert_equal_diff(expected.strip(), found.strip())
def step_impl(context, expected, found):
  expected = expand_scenario_variables(context, expected)
  if expected[0] != '/': expected = os.path.join(ROOT, 'test/fixtures', expected)
  with open(expected) as f:
    expected = f.read()

  if found[0] != '/': found = os.path.join(ROOT, 'test/fixtures', found)
  with open(found) as f:
    found = f.read()

  assert_equal_diff(expected.strip(), found.strip())
Beispiel #9
0
def step_impl(context, db, source):
  source = expand_scenario_variables(context, source)
  context.imported = source

  with open(os.path.join(ROOT, 'test', 'fixtures', source)) as f:
    data = json.load(f)
    items = data['items']
    #references = sum([ 1 + len(item.get('attachments', [])) + len(item.get('notes', [])) for item in items ])
    references = len(items)

  context.zotero.restart(timeout=context.timeout, db=db)
  assert_that(context.zotero.execute('return await Zotero.BetterBibTeX.TestSupport.librarySize()'), equal_to(references))

  # import preferences
  context.zotero.import_file(context, source, items=False)

  # check import
  export_library(context, expected = source)
Beispiel #10
0
def step_impl(context, references, attachments, source):
    source = expand_scenario_variables(context, source)
    context.imported = source
    assert_that(context.zotero.import_file(context, source),
                equal_to(references))
Beispiel #11
0
def step_impl(context, source):
    source = expand_scenario_variables(context, source)
    context.imported = source
    assert_that(context.zotero.import_file(context, source), equal_to(1))
Beispiel #12
0
def step_impl(context, pref, value):
    # bit of a cheat...
    if pref.endswith('.postscript'):
        value = expand_scenario_variables(context, value)
    context.zotero.preferences[pref] = context.zotero.preferences.parse(value)
Beispiel #13
0
def step_impl(context, expected):
    expected = expand_scenario_variables(context, expected)
    context.zotero.export_library(displayOptions=context.displayOptions,
                                  translator='BetterBibTeX JSON',
                                  expected=expected)
def step_impl(context, pref, value):
  # bit of a cheat...
  if pref.endswith('.postscript'):
    value = expand_scenario_variables(context, value)
  context.zotero.preferences[pref] = context.zotero.preferences.parse(value)
def step_impl(context, source):
  source = expand_scenario_variables(context, source)
  context.imported = source
  assert_that(context.zotero.import_file(context, source), equal_to(1))
Beispiel #16
0
def step_impl(context, references, source):
    source = expand_scenario_variables(context, source)
    assert_that(context.zotero.import_file(context, source, True),
                equal_to(references))
Beispiel #17
0
def step_impl(context, source, collection):
    source = expand_scenario_variables(context, source)
    assert_that(context.zotero.import_file(context, source, collection),
                equal_to(1))
def step_impl(context, references, attachments, source):
  source = expand_scenario_variables(context, source)
  context.imported = source
  assert_that(context.zotero.import_file(context, source), equal_to(references))