94 lines
1.9 KiB
Python
94 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
# coding: utf8
|
|
|
|
"""test_main.
|
|
|
|
Testing `main.py`
|
|
|
|
Author: frederic zind 2022-09-24
|
|
Licenses: GNU AGPL v3: http://www.gnu.org/licenses/
|
|
"""
|
|
import logging
|
|
from pytest import raises
|
|
|
|
import main
|
|
|
|
|
|
# Faking options from argparse
|
|
class FakeOptions: # pylint: disable=too-few-public-methods
|
|
"""Options object mock."""
|
|
|
|
debug = False
|
|
mapping = False
|
|
|
|
def __init__(self, options):
|
|
"""Built loggers options."""
|
|
if "debug" in options:
|
|
self.debug = True
|
|
if "mapping" in options:
|
|
self.mapping = True
|
|
|
|
|
|
# ###
|
|
# Testing setup_logging()
|
|
# ###
|
|
def test_logging_debug():
|
|
"""Logger level is DEBUG. Set up with --debug argument."""
|
|
options = FakeOptions(["debug"])
|
|
main.setup_logging(options)
|
|
|
|
assert isinstance((main.logger), logging.Logger)
|
|
assert main.logger.level == 10
|
|
|
|
|
|
def test_logging_default():
|
|
"""Logger level is INFO. Set up without arguments."""
|
|
options = FakeOptions([])
|
|
main.setup_logging(options)
|
|
|
|
assert isinstance((main.logger), logging.Logger)
|
|
assert main.logger.level == 20
|
|
|
|
|
|
# ###
|
|
# Testing parse_args()
|
|
# ###
|
|
def test_parse_args():
|
|
"""Defaults arguments are here."""
|
|
cli_options = main.parse_args(["--debug", "--mapping"])
|
|
assert cli_options.debug
|
|
assert cli_options.mapping
|
|
|
|
|
|
# ###
|
|
# Testing get_map_props()
|
|
# ###
|
|
def test_get_map_props():
|
|
"""This is an integration test.
|
|
|
|
It need credentials to guery LDP stream.
|
|
"""
|
|
pass
|
|
|
|
|
|
# ###
|
|
# Testing main()
|
|
# ###
|
|
def test_main_whithout_option():
|
|
"""Called without option."""
|
|
options = FakeOptions([])
|
|
|
|
with raises(RuntimeError):
|
|
main.main(options)
|
|
|
|
|
|
def test_main_demo_whith_mapping():
|
|
"""Called with mapping option.
|
|
|
|
`main()` just tranfers `get_map_props()` return: this test is not really useful
|
|
"""
|
|
options = FakeOptions(["mapping"])
|
|
response = main.main(options)
|
|
|
|
assert isinstance(response, list)
|