Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derra branch Mine functions I improved the coverage for #3780

Closed
wants to merge 10 commits into from
Binary file added logo/Picture10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/Picture11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/Picture12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/Picture13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/Picture14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/Picture15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/Picture16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/Picture5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/Picture6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/Picture7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/Picture8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/Picture9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/ass1_pic_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/ass1_pic_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/ass1_pic_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/ass1_pic_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 20 additions & 1 deletion nikola/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,33 @@ def wrap_in_color(self, record: logging.LogRecord) -> str:
# Initial configuration
class LoggingMode(enum.Enum):
"""Logging mode options."""

NORMAL = 0
STRICT = 1
QUIET = 2

branch_coverage_configure = {
"branch_1": False,
"branch_2": False,
"branch_3": False,
"branch_4": False
}


def configure_logging(logging_mode: LoggingMode = LoggingMode.NORMAL) -> None:
"""Configure logging for Nikola.

This method can be called multiple times, previous configuration will be overridden.
"""
if DEBUG:
branch_coverage_configure["branch_1"] = True
logging.root.level = logging.DEBUG
else:
branch_coverage_configure["branch_2"] = True
logging.root.level = logging.INFO

if logging_mode == LoggingMode.QUIET:
branch_coverage_configure["branch_3"] = True
logging.root.handlers = []
return

Expand All @@ -110,14 +120,23 @@ def configure_logging(logging_mode: LoggingMode = LoggingMode.NORMAL) -> None:

handlers = [handler]
if logging_mode == LoggingMode.STRICT:
branch_coverage_configure["branch_4"] = True
handlers.append(StrictModeExceptionHandler())

logging.root.handlers = handlers

def print_coverage_configure():
for branch, hit in branch_coverage_configure.items():
print(f"configure {branch} was {'hit' if hit else 'not hit'}")

def reset_coverage_configure():
for key in branch_coverage_configure:
branch_coverage_configure[key] = False

configure_logging()



# For compatibility with old code written with Logbook in mind
# TODO remove in v9
def patch_notice_level(logger: logging.Logger) -> logging.Logger:
Expand Down
23 changes: 22 additions & 1 deletion nikola/plugins/command/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@

class CommandStatus(Command):
"""Display site status."""

branch_coverage = {
"branch_1": False,
"branch_2": False,
"branch_3": False,
"branch_4": False
}


name = "status"

name = "status"
doc_purpose = "display site status"
doc_description = "Show information about the posts and site deployment."
doc_usage = '[-d|--list-drafts] [-m|--list-modified] [-p|--list-private] [-P|--list-published] [-s|--list-scheduled]'
Expand Down Expand Up @@ -163,9 +171,22 @@ def human_time(self, dt):
hours = dt.seconds / 60 // 60
minutes = dt.seconds / 60 - (hours * 60)
if days > 0:
self.branch_coverage["branch_1"] = True
return "{0:.0f} days and {1:.0f} hours".format(days, hours)
elif hours > 0:
self.branch_coverage["branch_2"] = True
return "{0:.0f} hours and {1:.0f} minutes".format(hours, minutes)
elif minutes:
self.branch_coverage["branch_3"] = True
return "{0:.0f} minutes".format(minutes)
self.branch_coverage["branch_4"] = True
return False


def report_coverage(self):
for branch, hit in self.branch_coverage.items():
print(f"{branch}: {'covered' if hit else 'not covered'}")

def reset_coverage(self):
for key in self.branch_coverage:
self.branch_coverage[key] = False
38 changes: 38 additions & 0 deletions tests/test_configure_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from nikola.log import configure_logging, print_coverage_configure, reset_coverage_configure, LoggingMode
from unittest.mock import patch


def test_normal_mode_debug():
reset_coverage_configure()
with patch('nikola.log.DEBUG', True):
configure_logging(logging_mode=LoggingMode.NORMAL)
print_coverage_configure()


def test_normal_mode_no_debug():
reset_coverage_configure()
configure_logging(logging_mode=LoggingMode.NORMAL)
print_coverage_configure()


def test_quiet_mode_debug():
reset_coverage_configure()
with patch('nikola.log.DEBUG', True):
configure_logging(logging_mode=LoggingMode.QUIET)
print_coverage_configure()

def test_quiet_mode_no_debug():
reset_coverage_configure()
configure_logging(logging_mode=LoggingMode.QUIET)
print_coverage_configure()

def test_strict_mode_debug():
reset_coverage_configure()
with patch('nikola.log.DEBUG', True):
configure_logging(logging_mode=LoggingMode.STRICT)
print_coverage_configure()

def test_strict_mode_no_debug():
reset_coverage_configure()
configure_logging(logging_mode=LoggingMode.STRICT)
print_coverage_configure()
54 changes: 54 additions & 0 deletions tests/test_configure_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from nikola.log import configure_logging, print_coverage_configure, reset_coverage_configure, LoggingMode
from unittest.mock import patch
import pytest

@pytest.mark.skip(reason="None")
def test_normal_mode_debug():
#reset_coverage_configure()
with patch('nikola.log.DEBUG', True):
configure_logging(logging_mode=LoggingMode.NORMAL)
#print_coverage_configure()

@pytest.mark.skip(reason="None")
def test_normal_mode_no_debug():
#reset_coverage_configure()
configure_logging(logging_mode=LoggingMode.NORMAL)
#print_coverage_configure()

@pytest.mark.skip(reason="None")
def test_quiet_mode_debug():
#reset_coverage_configure()
with patch('nikola.log.DEBUG', True):
configure_logging(logging_mode=LoggingMode.QUIET)
#print_coverage_configure()

@pytest.mark.skip(reason="None")
def test_quiet_mode_no_debug():
#reset_coverage_configure()
configure_logging(logging_mode=LoggingMode.QUIET)
#print_coverage_configure()

@pytest.mark.skip(reason="None")
def test_strict_mode_debug():
#reset_coverage_configure()
with patch('nikola.log.DEBUG', True):
configure_logging(logging_mode=LoggingMode.STRICT)
#print_coverage_configure()

@pytest.mark.skip(reason="None")
def test_strict_mode_no_debug():
#reset_coverage_configure()
configure_logging(logging_mode=LoggingMode.STRICT)
#print_coverage_configure()


def test_combined():
reset_coverage_configure()
test_normal_mode_debug()
test_normal_mode_no_debug()
test_quiet_mode_debug()
test_quiet_mode_no_debug()
test_strict_mode_debug()
test_strict_mode_no_debug
print_coverage_configure()

41 changes: 41 additions & 0 deletions tests/test_human.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest
from datetime import timedelta
from nikola.plugins.command.status import CommandStatus

@pytest.fixture(scope="module")
def command_status():
return CommandStatus()

@pytest.mark.skip(reason="None")
def test_days_branch(command_status):
print("\n test with 2 days 3 hours:")
result = command_status.human_time(timedelta(days=2, hours=3))
print(f"this is the result: ${result}")

@pytest.mark.skip(reason="None")
def test_hours_branch(command_status):
print("test with 4 hours 20 minutes:")
result = command_status.human_time(timedelta(hours=4, minutes=20))
print(f"this is the result: ${result}")


@pytest.mark.skip(reason="None")
def test_minutes_branch(command_status):
print("test with 15 minutes:")
result = command_status.human_time(timedelta(minutes=15))
print(f"this is the result: ${result}")

@pytest.mark.skip(reason="None")
def test_seconds_branch(command_status):
print("test with 0 seconds:")
result = command_status.human_time(timedelta(seconds=0))
print(f"this is the result: ${result}")

def test_combined(command_status):
command_status.reset_coverage()
test_days_branch(command_status)
test_hours_branch(command_status)
test_minutes_branch(command_status)
test_seconds_branch(command_status)
command_status.report_coverage()

3 changes: 3 additions & 0 deletions tests/test_report_coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from nikola.plugins.command.status import CommandStatus
command_status = CommandStatus()
command_status.report_coverage()