Skip to content

Commit 21e556d

Browse files
authored
improve config checks (#186)
* Breaking changes * `nichtparasoup config --check`'s "duplicate image crawler" is no longer a Warning but an Error. * renamed `nichtparasoup.testing.config.ConfigFileTest` to `ConfigFileTest` - without an "s". * Changes * `nichtparasoup config --check` now does a probe crawl. * Added * added additional test function: `nichtparasoup.testing.config.ConfigFileTest.probe()`.
1 parent 2766dd8 commit 21e556d

File tree

77 files changed

+254
-117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+254
-117
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: "Test"
22

3-
on:
3+
on:
44
push:
55
pull_request:
66
schedule:
@@ -24,16 +24,16 @@ jobs:
2424
uses: actions/setup-python@v1
2525
with:
2626
python-version: ${{ matrix.pyhon }}
27+
- name: Python version
28+
run: python --version
2729
- name: Install dependencies
2830
run: |
2931
python -m pip install --upgrade pip
30-
python -m pip install --upgrade setuptools tox
32+
python -m pip install --upgrade setuptools 'tox>3.10'
3133
- name: Test nichtparasoup
32-
run: |
33-
python -m tox -e py3-coverageXML
34+
run: python -m tox -e py3-coverageXML
3435
- name: "Test examples::nichtparasoup-imagecrawler-plugin"
35-
run: |
36-
python -m tox -c examples/nichtparasoup-imagecrawler-plugin/
36+
run: python -m tox -c examples/nichtparasoup-imagecrawler-plugin/
3737
- name: Upload coverage to Codecov
3838
# see https://github.com/codecov/codecov-action
3939
uses: codecov/codecov-action@v1

.github/workflows/pythonpublish.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ jobs:
1818
uses: actions/setup-python@v1
1919
with:
2020
python-version: '3.8'
21+
- name: Python version
22+
run: python --version
2123
- name: Install dependencies
2224
run: |
2325
python -m pip install --upgrade pip
24-
python -m pip install --upgrade setuptools tox
26+
python -m pip install --upgrade setuptools 'tox>3.10'
2527
- name: Test nichtparasoup
2628
run: |
2729
python -m tox -e py3

HISTORY.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33

44
## Unreleased
55

6+
### Breaking changes
7+
8+
* `nichtparasoup config --check`'s "duplicate image crawler" is no longer a Warning but an Error.
9+
* renamed `nichtparasoup.testing.config.ConfigFileTest` to `ConfigFileTest` - without an "s".
10+
611
### Changes
712

13+
* `nichtparasoup config --check` now does a probe crawl.
814
* class `ImageCrawlerInfo` lost support for positional arguments, supports keyword-arguments only - prepare future extensibility.
915
* class `Image` lost support for positional arguments, supports keyword-arguments only - prepare future extensibility.
1016

1117
### Added
1218

1319
* added image crawler for [pr0gramm](https://pr0gramm.com) - Read the [docs](./docs/imagecrawlers/pr0gramm.md).
20+
* added additional test function: `nichtparasoup.testing.config.ConfigFileTest.probe()`.
1421

1522

1623
## 2.2.2

docs/usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use a won config for the server. If omitted, the default is used. to write your
2121

2222
when you start _nichtparasoup_
2323
1. system will fill up cache by startup
24-
1. system starts up the webserver
24+
1. system starts up the web-server
2525
1. point your browser to the configured localhost:5000/ or whatever is configured in the config
2626
1. start page will request single images randomly by /get and show it
2727
1. when system's cache is empty, it will be refilled by the crawler automatically
@@ -41,14 +41,14 @@ for an eay handling this sub-command comes into play.
4141
`nichtparasoup config`
4242

4343
the following switches are available:
44-
* `--check` - validate a YAML config file
44+
* `--check` - validate and probe a YAML config file
4545
* `--dump` - dump YAML config into a file
4646

4747

4848
### check a config
4949

5050
check if a file is a valid config.
51-
will prompt promt errors and warnings, if any.
51+
will prompt prompt errors and warnings, if any.
5252

5353
`nichtparasoup config --check <file>`
5454

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11

22
[pytest]
3-
addopts = -v
3+
addopts = --verbose --strict-markers
44
testpaths = ./tests/
55
minversion = 3.0
66
console_output_style = classic
77
junit_family = xunit2
8+
markers =
9+
slow: marks tests as slow (deselect with '-m "not slow"')
10+
online: marks tests as "requires internet connection" (deselect with '-m "not online"')
11+

examples/nichtparasoup-imagecrawler-plugin/setup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
],
1515
),
1616
install_requires=[
17-
'nichtparasoup>=2.2',
17+
'nichtparasoup',
18+
# This example requires `nichtparasoup>=2.3`
19+
# You SHOULD write the min-version dependency in your real-world.
20+
# This was not done here, since its an in-dev example.
1821
],
1922
extras_require=dict(
2023
testing=[
2124
'mypy',
22-
'pytest',
25+
'pytest>=5,<5.3.4', # 5.3.4 has a bug: https://github.com/pytest-dev/pytest/issues/6517
2326
'coverage',
27+
'ddt',
2428
]
2529
),
2630
)

examples/nichtparasoup-imagecrawler-plugin/tests/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ stick to these rules:
5252
* write the test with`unittest`: test cases inherit `unittest.TestCase.`
5353
* each testable package/module has its own folder: name the test folder `test_*`
5454
* each testable function/class has its own file: name the test file `test_*.py`
55+
* test files are performed in alphabetical order - so add a number to have them ordered
5556
* name the test functions `test_*`

examples/nichtparasoup-imagecrawler-plugin/tests/test_nichtparasoup_placeholders/test_dummyimage.py renamed to examples/nichtparasoup-imagecrawler-plugin/tests/test_10_nichtparasoup_placeholders/test_dummyimage.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
from nichtparasoup.imagecrawler import BaseImageCrawler
77
from nichtparasoup.testing.imagecrawler import ImageCrawlerLoaderTest
88

9-
_dummyimage_right_config = {'width': 800, 'height': 600}
9+
_DUMMYIMAGE_RIGHT_CONFIG = {'width': 800, 'height': 600}
1010

1111

1212
class DummyImageConfigCorrect(unittest.TestCase):
1313

1414
def test__check_config_right_value(self) -> None:
1515
# arrange
16-
config_in = _dummyimage_right_config.copy()
16+
config_in = _DUMMYIMAGE_RIGHT_CONFIG.copy()
1717
# act
1818
config_out = DummyImage.check_config(config_in)
1919
# assert
@@ -23,7 +23,7 @@ def test__check_config_right_value(self) -> None:
2323
class DummyImageConfigWidthTest(unittest.TestCase):
2424

2525
def setUp(self) -> None:
26-
self._dummyimage_right_config_wo_width = _dummyimage_right_config.copy()
26+
self._dummyimage_right_config_wo_width = _DUMMYIMAGE_RIGHT_CONFIG.copy()
2727
del self._dummyimage_right_config_wo_width["width"]
2828

2929
def tearDown(self) -> None:
@@ -58,7 +58,7 @@ def test__check_config_wrong_value(self) -> None:
5858
class DummyImageConfigHeightTest(unittest.TestCase):
5959

6060
def setUp(self) -> None:
61-
self._dummyimage_right_config_wo_height = _dummyimage_right_config.copy()
61+
self._dummyimage_right_config_wo_height = _DUMMYIMAGE_RIGHT_CONFIG.copy()
6262
del self._dummyimage_right_config_wo_height["height"]
6363

6464
def tearDown(self) -> None:
@@ -94,7 +94,7 @@ class DummyImageCrawlTest(unittest.TestCase):
9494

9595
def test_crawl(self) -> None:
9696
# arrange
97-
crawler = DummyImage(**_dummyimage_right_config)
97+
crawler = DummyImage(**_DUMMYIMAGE_RIGHT_CONFIG)
9898
# act
9999
images_crawled = crawler.crawl()
100100
images_crawled_len = len(images_crawled)
@@ -112,8 +112,8 @@ def test_description_config(self) -> None:
112112
description = DummyImage.info()
113113
# assert
114114
assert isinstance(description.config, dict)
115-
for config_key in _dummyimage_right_config.keys():
116-
self.assertTrue(config_key in description.config, config_key)
115+
for config_key in _DUMMYIMAGE_RIGHT_CONFIG.keys():
116+
self.assertIn(config_key, description.config)
117117

118118

119119
class DummyImageLoaderTest(ImageCrawlerLoaderTest):
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from glob import glob
2+
from os.path import basename, dirname, join as path_join, realpath
3+
4+
import pytest # type: ignore
5+
from ddt import ddt, idata, unpack # type: ignore
6+
7+
from nichtparasoup.testing.config import ConfigFileTest
8+
9+
10+
@ddt
11+
class ShippedExampleConfigFileTest(ConfigFileTest):
12+
__EXAMPLE_DIR = path_join(dirname(__file__), '..', '..', 'examples')
13+
__EXAMPLE_FILES = glob(path_join(__EXAMPLE_DIR, '*.*'), recursive=False)
14+
15+
def test_has_examples(self) -> None:
16+
self.assertGreater(len(self.__class__.__EXAMPLE_FILES), 0)
17+
18+
@pytest.mark.online # type: ignore # probing goes over the internet
19+
@pytest.mark.slow # type: ignore # probing might be slow
20+
@idata((basename(file),) for file in __EXAMPLE_FILES) # type: ignore
21+
@unpack # type: ignore
22+
def test_example(self, filename: str) -> None:
23+
file = realpath(path_join(self.__class__.__EXAMPLE_DIR, filename))
24+
self.validate(file)
25+
self.probe(file)

examples/nichtparasoup-imagecrawler-plugin/tests/test_examples/test_shipped_config_files.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)