Skip to content

Commit

Permalink
Merge pull request #41 from kinegratii/develop
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
kinegratii authored Mar 14, 2022
2 parents 272852e + 578d8f2 commit 467d56a
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 49 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
![Python package](https://github.com/kinegratii/borax/workflows/Python%20package/badge.svg)
![Codecov](https://codecov.io/github/kinegratii/borax/coverage.svg)
![GitHub license](https://img.shields.io/github/license/kinegratii/borax)
![Document](https://img.shields.io/badge/%E6%96%87%E6%A1%A3-docsify%20%7C%20%E8%AF%AD%E9%9B%80-brightgreen)

![Document](https://img.shields.io/badge/%E6%96%87%E6%A1%A3-docsify-brightgreen)
[![borax](https://snyk.io/advisor/python/borax/badge.svg)](https://snyk.io/advisor/python/borax)


## 概述 (Overview)
Expand Down
2 changes: 1 addition & 1 deletion borax/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# coding=utf8

__version__ = '3.5.3'
__version__ = '3.5.4'
__author__ = 'kinegratii'
4 changes: 2 additions & 2 deletions borax/datasets/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from functools import partial
from itertools import tee

__all__ = ['Empty', 'fetch', 'ifetch', 'fetch_single', 'ifetch_multiple', 'ifetch_single', 'fetch_as_dict']
__all__ = ['Empty', 'bget', 'fetch', 'ifetch', 'fetch_single', 'ifetch_multiple', 'ifetch_single', 'fetch_as_dict']


class Empty:
Expand All @@ -18,7 +18,7 @@ class Empty:
def bget(obj, key, default=Empty):
try:
return obj[key]
except KeyError:
except (TypeError, KeyError):
pass
try:
return getattr(obj, key)
Expand Down
4 changes: 2 additions & 2 deletions borax/htmls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding=utf8

import html
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Union


def _escape(s):
Expand Down Expand Up @@ -58,7 +58,7 @@ def html_params(**kwargs) -> str:


def html_tag(tag_name: str, content: str = None,
*, id_: str = None, style: Dict = None, class_: Optional[List] = None, **kwargs) -> HTMLString:
*, id_: str = None, style: Dict = None, class_: Union[List, str, None] = None, **kwargs) -> HTMLString:
"""生成元素的html字符串"""
kw = {}
if id_:
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
![Python package](https://github.com/kinegratii/borax/workflows/Python%20package/badge.svg)
![Codecov](https://codecov.io/github/kinegratii/borax/coverage.svg)
![GitHub license](https://img.shields.io/github/license/kinegratii/borax)
![Document](https://img.shields.io/badge/%E6%96%87%E6%A1%A3-docsify%20%7C%20%E8%AF%AD%E9%9B%80-brightgreen)

![Document](https://img.shields.io/badge/%E6%96%87%E6%A1%A3-docsify-brightgreen)
[![borax](https://snyk.io/advisor/python/borax/badge.svg)](https://snyk.io/advisor/python/borax)



Expand Down Expand Up @@ -38,4 +38,4 @@ Borax 是一个Python3工具集合库。
## 开发(Development)

- **代码仓库**[Github](https://github.com/kinegratii/borax/) | [Gitee (镜像)](https://gitee.com/kinegratii/borax)
- **项目开发**: [版本日志](changelog) | [技术文档](develope/develope)
- **项目开发**: [版本日志](changelog) | [技术文档(外链)](http://fd8cc08f.wiz06.com/wapp/pages/view/share/s/3Zzc2f0LJQ3w2TWIQb0ZMSna1zg4gs1vPQmb2vlh9M2zhqK8)
3 changes: 1 addition & 2 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@
- **● 发布日志**
- [v3.5](release-note/v350)
- **● 项目开发**
- [版本日志](changelog)
- [技术文档](develope/develope)
- [版本日志](changelog)
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 更新日志

## v3.5.4 (20220314)

- `borax.htmls`
- `html_tag` 函数css参数支持str类型(函数逻辑已支持,本次仅添加typing hints)
- `borax.datasets.fetch` 模块
- 修正 `fetch` 解析错误的bug ([#39](https://github.com/kinegratii/borax/issues/39)

## v3.5.3 (20220303)

- `borax.serialize.cjson`
Expand Down
3 changes: 0 additions & 3 deletions docs/develope/develope.md

This file was deleted.

32 changes: 0 additions & 32 deletions pyproject.toml

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
author='kinegratii',
author_email='zhenwei.yan@hotmail.com',
classifiers=lib_classifiers,
description='A tool collections for Python3.',
description='A tool collections.(Chinese-Lunar-Calendars/Python-Patterns)',
long_description=long_description,
long_description_content_type='text/markdown'
)
18 changes: 17 additions & 1 deletion tests/test_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import unittest

from borax.datasets.fetch import fetch, fetch_single, ifetch_multiple, fetch_as_dict
from borax.datasets.fetch import fetch, fetch_single, ifetch_multiple, fetch_as_dict, bget

DICT_LIST_DATA = [
{'id': 282, 'name': 'Alice', 'age': 30, 'sex': 'female'},
Expand All @@ -12,6 +12,22 @@
]


class Point:
def __init__(self, x, y):
self.x = x
self.y = y


class GetterTestCase(unittest.TestCase):
def test_default_getter(self):
p = Point(1, 2)
self.assertEqual(1, bget(p, 'x'))
p2 = [2, 4]
self.assertEqual(4, bget(p2, 1))
p3 = {'x': 5, 'y': 10}
self.assertEqual(5, bget(p3, 'x'))


class FetchTestCase(unittest.TestCase):
def test_fetch_single(self):
names = fetch_single(DICT_LIST_DATA, 'name')
Expand Down
15 changes: 15 additions & 0 deletions tests/test_htmls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
from borax.htmls import HTMLString, html_tag


class HtmlStringTestCase(unittest.TestCase):
def test_html_string(self):
s = HTMLString('<div>Hello</div>')
s2 = HTMLString(s)
self.assertEqual(s.__html__(), s2.__html__())


class HtmlTagTest(unittest.TestCase):
def test_html_tags(self):
html = html_tag('img', id_='idDemoImg', src='/demo.png')
Expand All @@ -20,3 +27,11 @@ def test_fixed_html(self):
self.assertEqual('<div id="demo" style="width:2px;"></div>',
html_tag('div', id_='demo', style={'width': '2px'}))
self.assertEqual('<div id="demo" class="a1 a2"></div>', html_tag('div', id_='demo', class_=['a1', 'a2']))

def test_css_attr(self):
self.assertEqual('<div class="one two"></div>', html_tag('div', class_=['one', 'two']))
self.assertEqual('<div class="one two"></div>', html_tag('div', class_='one two'))

def test_bool_attr(self):
self.assertEqual('<div id="sk" checked>Demo</div>', html_tag('div', id_='sk', content='Demo', checked=True))
self.assertEqual('<div id="sk">Demo</div>', html_tag('div', id_='sk', content='Demo', checked=False))

0 comments on commit 467d56a

Please sign in to comment.