Skip to content

Commit

Permalink
Version 4.2.2 (cdgriffith#143)
Browse files Browse the repository at this point in the history
* Fixing `default_box` doesn't first look for safe attributes before falling back to default (thanks to Pymancer)
* Changing from TravisCI to Github Actions
  • Loading branch information
cdgriffith authored Mar 11, 2020
1 parent ba48dc7 commit 572c1b5
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 72 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
49 changes: 49 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Tests

on:
push:
branches: [ master, development ]
pull_request:
branches: [ master, development ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
pip install coveralls
- name: Lint with flake8
run: |
pip install flake8 flake8-print
# stop the build if there are Python syntax errors or undefined names
flake8 box --count --select=E9,F63,F7,F82,T001,T002,T003,T004 --show-source --statistics
# exit-zero treats all errors as warnings.
flake8 . --count --exit-zero --max-complexity=20 --max-line-length=120 --statistics
- name: Test with pytest
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: |
pytest --cov=box test/
coveralls
- name: Check distrubiton log description
run: |
pip install setuptools wheel twine
python setup.py sdist bdist_wheel
twine check dist/*
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ Suggestions and bug reporting:
- Marcelo Huerta (richieadler)
- Wenbo Zhao (zhaowb)
- Yordan Ivanov (iordanivanov)
- Lei (NEOOOOOOOOOO)
- Lei (NEOOOOOOOOOO)
- Pymancer
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ Changelog
=========


Version 4.2.2
-------------

* Fixing `default_box` doesn't first look for safe attributes before falling back to default (thanks to Pymancer)
* Changing from TravisCI to Github Actions

Version 4.2.1
-------------

Expand Down
2 changes: 1 addition & 1 deletion box/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: UTF-8 -*-

__author__ = 'Chris Griffith'
__version__ = '4.2.1'
__version__ = '4.2.2'

from box.box import Box
from box.box_list import BoxList
Expand Down
4 changes: 2 additions & 2 deletions box/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,12 @@ def __getattr__(self, item):
raise BoxKeyError(item) from None
if item == '_box_config':
raise BoxError('_box_config key must exist') from None
if self._box_config['default_box']:
return self.__get_default(item)
if self._box_config['conversion_box']:
safe_key = self._safe_attr(item)
if safe_key in self._box_config['__safe_keys']:
return self.__getitem__(self._box_config['__safe_keys'][safe_key])
if self._box_config['default_box']:
return self.__get_default(item)
raise BoxKeyError(str(err)) from None
return value

Expand Down
11 changes: 0 additions & 11 deletions test/common.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import unittest
import json
import os
import shutil
import sys
import copy
import pytest
from pathlib import Path

import ruamel.yaml as yaml
import toml

import box
from box import *

PY3 = sys.version_info >= (3, 0)

test_root = os.path.abspath(os.path.dirname(__file__))
Expand Down
42 changes: 18 additions & 24 deletions test/test_box.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Test files gathered from json.org and yaml.org

from multiprocessing import Process, Queue
import pytest
import copy
import json
import os
import pickle
import shutil
from multiprocessing import Queue
from pathlib import Path

try:
from test.common import *
except ImportError:
from .common import *
import pytest
import ruamel.yaml as yaml

from box import box
from box import Box, BoxError, BoxKeyError, BoxList, SBox, ConfigBox
from test.common import (test_dict, extended_test_dict, tmp_dir, tmp_json_file, tmp_yaml_file, movie_data,
data_json_file, data_yaml_file, test_root)


def mp_queue_test(q):
Expand Down Expand Up @@ -84,23 +89,6 @@ def test_recursive_tuples(self):
assert isinstance(out[1][2], tuple)
assert out[1][0] == {'second': 'b'}

def test_to_json(self):
m_file = os.path.join(tmp_dir, "movie_data")
movie_string = box._to_json(movie_data)
assert "Rick Moranis" in movie_string
box._to_json(movie_data, filename=m_file)
assert "Rick Moranis" in open(m_file).read()
assert json.load(open(m_file)) == json.loads(movie_string)

def test_to_yaml(self):
m_file = os.path.join(tmp_dir, "movie_data")
movie_string = box._to_yaml(movie_data)
assert "Rick Moranis" in movie_string
box._to_yaml(movie_data, filename=m_file)
assert "Rick Moranis" in open(m_file).read()
assert yaml.load(open(m_file), Loader=yaml.SafeLoader) == yaml.load(
movie_string, Loader=yaml.SafeLoader)

def test_box(self):
bx = Box(**test_dict)
assert bx.key1 == test_dict['key1']
Expand Down Expand Up @@ -439,6 +427,12 @@ def test_default_box(self):
assert bx9.test == s
assert id(bx9.test) != id(s)

bx10 = Box({'from': 'here'}, default_box=True)
assert bx10.xfrom == 'here'
bx10.xfrom = 5
assert bx10.xfrom == 5
assert bx10 == {'from': 5}

# Issue#59 https://github.com/cdgriffith/Box/issues/59 "Treat None values as non existing keys for default_box"
def test_default_box_none_transforms(self):
bx4 = Box({"noneValue": None, "inner": {"noneInner": None}}, default_box=True, default_box_attr="issue#59")
Expand Down
14 changes: 9 additions & 5 deletions test/test_box_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
# -*- coding: UTF-8 -*-
# Test files gathered from json.org and yaml.org

import pytest
import json
import os
import shutil
from pathlib import Path

import pytest
import ruamel.yaml as yaml
import toml

from box import BoxList, Box, BoxError

try:
from test.common import *
except ImportError:
from .common import *
from test.common import tmp_dir, test_root


class TestBoxList:
Expand Down
7 changes: 3 additions & 4 deletions test/test_config_box.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python
try:
from test.common import *
except ImportError:
from .common import *

from box import Box, ConfigBox
from test.common import test_dict


class TestConfigBox:
Expand Down
31 changes: 26 additions & 5 deletions test/test_converters.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/usr/bin/env python
try:
from test.common import *
except ImportError:
from .common import *
import os
import shutil
from pathlib import Path
import json

import pytest
import ruamel.yaml as yaml

from box import BoxError
from box.converters import _to_toml, _from_toml, _to_json, _to_yaml
from test.common import tmp_dir, movie_data

from box.converters import _to_toml, _from_toml

toml_string = """[movies.Spaceballs]
imdb_stars = 7.1
Expand Down Expand Up @@ -61,3 +66,19 @@ def test_from_toml_file(self):
def test_bad_from_toml(self):
with pytest.raises(BoxError):
_from_toml()

def test_to_json(self):
m_file = os.path.join(tmp_dir, "movie_data")
movie_string = _to_json(movie_data)
assert "Rick Moranis" in movie_string
_to_json(movie_data, filename=m_file)
assert "Rick Moranis" in open(m_file).read()
assert json.load(open(m_file)) == json.loads(movie_string)

def test_to_yaml(self):
m_file = os.path.join(tmp_dir, "movie_data")
movie_string = _to_yaml(movie_data)
assert "Rick Moranis" in movie_string
_to_yaml(movie_data, filename=m_file)
assert "Rick Moranis" in open(m_file).read()
assert yaml.load(open(m_file), Loader=yaml.SafeLoader) == yaml.load(movie_string, Loader=yaml.SafeLoader)
4 changes: 2 additions & 2 deletions test/test_from_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from pathlib import Path

import pytest
from box import box_from_file

from test.common import *
from box import box_from_file, Box, BoxList, BoxError
from test.common import test_root


class TestFromFile:
Expand Down
10 changes: 6 additions & 4 deletions test/test_sbox.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python
try:
from test.common import *
except ImportError:
from .common import *
import json

import ruamel.yaml as yaml

from box import SBox, Box
from test.common import test_dict


class TestSBox:
Expand Down

0 comments on commit 572c1b5

Please sign in to comment.