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)
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)