コード例 #1
0
    def export_library(self,
                       translator,
                       displayOptions={},
                       collection=None,
                       output=None,
                       expected=None,
                       resetCache=False):
        assert not displayOptions.get(
            'keepUpdated', False) or output  # Auto-export needs a destination
        displayOptions['Normalize'] = True

        if translator.startswith('id:'):
            translator = translator[len('id:'):]
        else:
            translator = self.translators.byName[translator].translatorID

        found = self.execute(
            'return await Zotero.BetterBibTeX.TestSupport.exportLibrary(translatorID, displayOptions, path, collection)',
            translatorID=translator,
            displayOptions=displayOptions,
            path=output,
            collection=collection)
        if resetCache:
            self.execute('Zotero.BetterBibTeX.TestSupport.resetCache()')

        if expected is None: return

        if output:
            with open(output) as f:
                found = f.read()

        expected_file = expected
        expected, loaded_file = self.load(expected_file, True)
        exported = self.exported(loaded_file, found)

        if expected_file.endswith('.csl.json'):
            assert_equal_diff(
                json.dumps(expected, sort_keys=True, indent='  '),
                json.dumps(json.loads(found), sort_keys=True, indent='  '))

        elif expected_file.endswith('.csl.yml'):
            assert_equal_diff(serialize(expected),
                              serialize(yaml.load(io.StringIO(found))))

        elif expected_file.endswith('.json'):
            # TODO: clean lib and test against schema

            expected = Library(expected)
            found = Library(json.loads(found, object_pairs_hook=OrderedDict))
            assert_equal_diff(serialize(expected), serialize(found))

        else:
            assert_equal_diff(expected.strip(), found.strip())

        self.exported(exported)
コード例 #2
0
  def export_library(self, translator, displayOptions = {}, collection = None, output = None, expected = None, resetCache = False):
    assert not displayOptions.get('keepUpdated', False) or output # Auto-export needs a destination

    if translator.startswith('id:'):
      translator = translator[len('id:'):]
    else:
      translator = self.translators.byName[translator].translatorID

    found = self.execute('return await Zotero.BetterBibTeX.TestSupport.exportLibrary(translatorID, displayOptions, path, collection)',
      translatorID=translator,
      displayOptions=displayOptions,
      path=output,
      collection=collection
    )
    if resetCache: self.execute('Zotero.BetterBibTeX.TestSupport.resetCache()')

    if expected is None: return

    if output:
      with open(output) as f:
        found = f.read()

    expected, ext = self.expand_expected(expected)
    with open(expected) as f:
      expected = f.read()

    if ext == '.csl.json':
      with open('exported.csl.json', 'w') as f: f.write(found)
      return compare(json.loads(expected), json.loads(found))

    elif ext == '.csl.yml':
      with open('exported.csl.yml', 'w') as f: f.write(found)
      assert_equal_diff(
        serialize(yaml.load(io.StringIO(expected))),
        serialize(yaml.load(io.StringIO(found)))
      )
      return

    elif ext == '.json':
      with open('exported.json', 'w') as f: f.write(found)

      found = normalizeJSON(json.loads(found))
      expected = normalizeJSON(json.loads(expected))

      if len(expected['items']) < 30 or len(found['items']) < 30:
        assert_equal_diff(serialize(expected), serialize(found))
        return
      else:
        assert_equal_diff(serialize({ **expected, 'items': []}), serialize({ **found, 'items': []}))
        return compare(expected['items'], found['items'])

    with open('exported.txt', 'w') as f: f.write(found)
    expected = expected.strip()
    found = found.strip()

    assert_equal_diff(expected, found)
コード例 #3
0
    def export_library(self,
                       translator,
                       displayOptions={},
                       collection=None,
                       output=None,
                       expected=None,
                       resetCache=False):
        assert not displayOptions.get(
            'keepUpdated', False) or output  # Auto-export needs a destination

        if translator.startswith('id:'):
            translator = translator[len('id:'):]
        else:
            translator = self.translators.byName[translator].translatorID

        found = self.execute(
            'return await Zotero.BetterBibTeX.TestSupport.exportLibrary(translatorID, displayOptions, path, collection)',
            translatorID=translator,
            displayOptions=displayOptions,
            path=output,
            collection=collection)
        if resetCache:
            self.execute('Zotero.BetterBibTeX.TestSupport.resetCache()')

        if expected is None: return

        if output:
            with open(output) as f:
                found = f.read()

        expected, ext = self.expand_expected(expected)
        with open(expected) as f:
            expected = f.read()

        if ext == '.csl.json':
            with open('exported.csl.json', 'w') as f:
                f.write(found)
            return compare(json.loads(expected), json.loads(found))

        elif ext == '.csl.yml':
            with open('exported.csl.yml', 'w') as f:
                f.write(found)
            assert_equal_diff(serialize(yaml.load(io.StringIO(expected))),
                              serialize(yaml.load(io.StringIO(found))))
            return

        elif ext == '.json':
            with open('exported.json', 'w') as f:
                f.write(found)

            found = normalizeJSON(json.loads(found))
            expected = normalizeJSON(json.loads(expected))

            if len(expected['items']) < 30 or len(found['items']) < 30:
                assert_equal_diff(serialize(expected), serialize(found))
                return
            else:
                assert_equal_diff(serialize({
                    **expected, 'items': []
                }), serialize({
                    **found, 'items': []
                }))
                return compare(expected['items'], found['items'])

        with open('exported.txt', 'w') as f:
            f.write(found)
        expected = expected.strip()
        found = found.strip()

        assert_equal_diff(expected, found)
コード例 #4
0
    def export_library(self,
                       translator,
                       displayOptions={},
                       collection=None,
                       output=None,
                       expected=None,
                       resetCache=False):
        assert not displayOptions.get(
            'keepUpdated', False) or output  # Auto-export needs a destination

        if translator.startswith('id:'):
            translator = translator[len('id:'):]
        else:
            translator = self.translators.byName[translator].translatorID

        found = self.execute(
            'return await Zotero.BetterBibTeX.TestSupport.exportLibrary(translatorID, displayOptions, path, collection)',
            translatorID=translator,
            displayOptions=displayOptions,
            path=output,
            collection=collection)
        if resetCache:
            self.execute('Zotero.BetterBibTeX.TestSupport.resetCache()')

        if expected is None: return

        if output:
            with open(output) as f:
                found = f.read()

        expected, ext = self.expand_expected(expected)
        loaded(expected)
        exported = os.path.join(
            EXPORTED,
            os.path.basename(os.path.dirname(expected)) + '-' +
            os.path.basename(expected))

        with open(expected) as f:
            expected = f.read()

        if ext == '.csl.json':
            with open(exported, 'w') as f:
                f.write(found)
            assert_equal_diff(serialize(json.loads(expected)),
                              serialize(json.loads(found)))
            os.remove(exported)
            return

        elif ext == '.csl.yml':
            with open(exported, 'w') as f:
                f.write(found)
            assert_equal_diff(serialize(yaml.load(io.StringIO(expected))),
                              serialize(yaml.load(io.StringIO(found))))
            os.remove(exported)
            return

        elif ext == '.json':
            with open(exported, 'w') as f:
                f.write(found)

            found = Library(json.loads(found))
            expected = Library(json.loads(expected))

            assert_equal_diff(serialize(expected), serialize(found))

            os.remove(exported)
            return

        with open(exported, 'w') as f:
            f.write(found)
        expected = expected.strip()
        found = found.strip()

        assert_equal_diff(expected, found)
        os.remove(exported)
        return