Skip to content

Commit

Permalink
Merge pull request #55 from ocefpaf/appveyor
Browse files Browse the repository at this point in the history
Appveyor
  • Loading branch information
ocefpaf authored Mar 7, 2019
2 parents d26181c + 52ceac4 commit c3623fd
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 36 deletions.
30 changes: 30 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
build: false

environment:
matrix:
- PYTHON: "C:\\Miniconda36-x64"
PY: 3.6

init:
- "ECHO %PYTHON_VERSION% %MINICONDA%"

install:
# Install and configure miniconda.
- "set PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
- conda config --set always_yes yes --set changeps1 no --set show_channel_urls true
- conda update conda --quiet
- conda config --add channels conda-forge --force
- conda install pycryptosat
- conda config --set safety_checks disabled

# Create the test env.
- conda create --name TEST python=%PY% --file requirements.txt --file requirements-dev.txt
- activate TEST

# Debug.
- conda info --all
- conda list

test_script:
- pip install -e . --no-deps --force-reinstall
- pytest -n 2 -rxXs -m "not headless" tests
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ examples/foo.html

# documentation builds
docs/_build

geckodriver.log
17 changes: 6 additions & 11 deletions branca/colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,23 @@

import json
import math
import os

from branca.element import ENV, Figure, JavascriptLink, MacroElement
from branca.utilities import legend_scaler

from jinja2 import Template

import pkg_resources

from six import binary_type, text_type


resource_package = __name__
resource_path_schemes = '/_schemes.json'
resource_path_cnames = '/_cnames.json'
rootpath = os.path.abspath(os.path.dirname(__file__))

cnames_string = pkg_resources.resource_stream(
resource_package, resource_path_cnames).read().decode()
_cnames = json.loads(cnames_string)
with open(os.path.join(rootpath, '_cnames.json')) as f:
_cnames = json.loads(f.read())

schemes_string = pkg_resources.resource_stream(
resource_package, resource_path_schemes).read().decode()
_schemes = json.loads(schemes_string)
with open(os.path.join(rootpath, '_schemes.json')) as f:
_schemes = json.loads(f.read())


def _is_hex(x):
Expand Down
37 changes: 16 additions & 21 deletions branca/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import base64
import json
import math
import os
import struct
import zlib

from jinja2 import Environment, PackageLoader

import pkg_resources

from six import binary_type, text_type

Expand All @@ -32,6 +32,9 @@
np = None


rootpath = os.path.abspath(os.path.dirname(__file__))


def get_templates():
"""Get Jinja templates."""
return Environment(loader=PackageLoader('branca', 'templates'))
Expand Down Expand Up @@ -131,22 +134,14 @@ def color_brewer(color_code, n=6):
core_color_code = base_code + '_' + str(n).zfill(2)
color_reverse = False

resource_package = __name__
resource_path_schemes = '/_schemes.json'
resource_path_scheme_info = '/_cnames.json'
resource_path_scheme_base_codes = '/scheme_base_codes.json'

schemes_string = pkg_resources.resource_stream(
resource_package, resource_path_schemes).read().decode()
schemes = json.loads(schemes_string)
with open(os.path.join(rootpath, '_schemes.json')) as f:
schemes = json.loads(f.read())

scheme_info_string = pkg_resources.resource_stream(
resource_package, resource_path_scheme_info).read().decode()
scheme_info = json.loads(scheme_info_string)
with open(os.path.join(rootpath, '_cnames.json')) as f:
scheme_info = json.loads(f.read())

core_schemes_string = pkg_resources.resource_stream(
resource_package, resource_path_scheme_base_codes).read().decode()
core_schemes = json.loads(core_schemes_string)['codes']
with open(os.path.join(rootpath, 'scheme_base_codes.json')) as f:
core_schemes = json.loads(f.read())['codes']

if base_code not in core_schemes:
raise ValueError(base_code + ' is not a valid ColorBrewer code')
Expand Down Expand Up @@ -304,8 +299,8 @@ def colormap(x):
height, width, nblayers = array.shape

if nblayers not in [1, 3, 4]:
raise ValueError('Data must be NxM (mono), '
'NxMx3 (RGB), or NxMx4 (RGBA)')
raise ValueError('Data must be NxM (mono), '
'NxMx3 (RGB), or NxMx4 (RGBA)')
assert array.shape == (height, width, nblayers)

if nblayers == 1:
Expand Down Expand Up @@ -337,10 +332,10 @@ def colormap(x):
for i in range(height)])

def png_pack(png_tag, data):
chunk_head = png_tag + data
return (struct.pack('!I', len(data)) +
chunk_head +
struct.pack('!I', 0xFFFFFFFF & zlib.crc32(chunk_head)))
chunk_head = png_tag + data
return (struct.pack('!I', len(data)) +
chunk_head +
struct.pack('!I', 0xFFFFFFFF & zlib.crc32(chunk_head)))

return b''.join([
b'\x89PNG\r\n\x1a\n',
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ flake8-print
flake8-quotes
nbsphinx
pytest
pytest-xdist
selenium
sphinx
3 changes: 3 additions & 0 deletions tests/test_iframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import branca.element as elem

import pytest

from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options

Expand All @@ -21,6 +23,7 @@ def test_create_iframe():
iframe.render()


@pytest.mark.headless
def test_rendering_utf8_iframe():
iframe = elem.IFrame(html=u'<p>Cerrahpaşa Tıp Fakültesi</p>')

Expand Down
9 changes: 5 additions & 4 deletions tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class TestNotebooks(object):
_nblist = [x for x in os.listdir(_filepath) if x.endswith('.ipynb')]

for fn in TestNotebooks._nblist:
setattr(TestNotebooks,
'test_'+branca.utilities._camelify(fn[:-6]),
NotebookTester(TestNotebooks._filepath+fn).__call__
)
setattr(
TestNotebooks,
'test_'+branca.utilities._camelify(fn[:-6]),
NotebookTester(TestNotebooks._filepath+fn).__call__
)

0 comments on commit c3623fd

Please sign in to comment.