Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Fix build breakage introduced in npm syncing #4173

Merged
merged 2 commits into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gratipay/package_managers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
NULL = uuid.uuid4().hex


def import_ijson():
import ijson.backends.yajl2_cffi as ijson
return ijson


def arrayize(seq):
"""Given a sequence of str, return a Postgres array literal str.
"""
Expand Down Expand Up @@ -48,7 +53,7 @@ def serialize_one(out, package):
def serialize(args):
"""Consume raw JSON from the npm registry and spit out CSV for Postgres.
"""
import ijson.backends.yajl2_cffi as ijson
ijson = import_ijson()

path = args.path
parser = ijson.parse(open(path))
Expand Down
23 changes: 20 additions & 3 deletions tests/py/test_npm_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

from subprocess import Popen, PIPE

import pytest
from gratipay.utils import markdown
from gratipay.testing import Harness
from gratipay.package_managers import readmes
from gratipay.package_managers import readmes, sync


def load(raw):
Expand All @@ -17,6 +19,22 @@ def load(raw):
).communicate(serialized)[0]


try:
sync.import_ijson()
except ImportError:
missing_ijson = True
else:
missing_ijson = False

try:
markdown.marky('test')
except OSError:
missing_marky_markdown = True
else:
missing_marky_markdown = False

@pytest.mark.skipif(missing_ijson, reason="missing ijson")
@pytest.mark.skipif(missing_marky_markdown, reason="missing marky-markdown")
class Tests(Harness):

def test_packages_starts_empty(self):
Expand Down Expand Up @@ -101,8 +119,7 @@ def fetch(name):
package = self.db.one('SELECT * FROM packages')
assert package.name == 'foo-package'
assert package.description == 'A package'
assert package.readme == '<h1 id="user-content-greetings-program" class="deep-link">' \
'<a href="#greetings-program">Greetings, program!</a></h1>\n'
assert package.readme == '<h1><a id="user-content-greetings-program" class="deep-link" href="#greetings-program"><svg aria-hidden="true" class="deep-link-icon" height="16" version="1.1" width="16"><path d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Greetings, program!</h1>\n'
assert package.readme_raw == '# Greetings, program!'
assert package.readme_type == 'x-markdown/npm'
assert package.emails == []