Skip to content

Commit

Permalink
Merge pull request #40 from ryukinix/improve-coverage
Browse files Browse the repository at this point in the history
Improving coverage
  • Loading branch information
ryukinix committed Dec 27, 2017
2 parents 7d6e7f2 + 38a81ef commit ddf473d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
12 changes: 11 additions & 1 deletion .coveragerc
Expand Up @@ -7,4 +7,14 @@ exclude_lines =
if __name__ == .__main__.:
unittest.main()
pass
def __getattr__(self, attr):
def __getattr__(self, attr):

[run]
omit =
# omit anything in a .local directory anywhere
*/.local/*
# omit everything in /usr
/usr/*
# omit this single file
utils/tirefire.py
setup.py
22 changes: 20 additions & 2 deletions decorating/monitor.py
Expand Up @@ -38,12 +38,30 @@ def start(self):
def stop(self):
sys.stdout = sys.__stdout__

def clear(self):
self.data = []

@property
def data(self):
return self.stream.data

@data.setter
def data(self, data):
self.stream.data = data

@classmethod
def __call__(cls, func):
import warnings
warnings.warn(("MonitorStdout doesn't works as decorator. "
"Use it as contextmanager by 'with' syntax instead"))
return func


monitor_stdout = MonitorStdout()


def test():
def test(): # pragma: no cover
with monitor_stdout:
print('test')

print(monitor_stdout.stream.data)
print(monitor_stdout.data)
6 changes: 3 additions & 3 deletions tests/test_decorator.py 100644 → 100755
Expand Up @@ -69,10 +69,10 @@ class TestWiredDecorator(unittest.TestCase):

def test_deco_layer1(self):
"""Test decorator with basic usage"""
with writing(0.1):
with writing(0.01):
@self.wired('Chisa')
def _knights():
with writing(0.3):
with writing(0.03):
print('suiciding...')

_knights()
Expand All @@ -96,7 +96,7 @@ def _lain():
print("λ- (open-world 'next-life)")

with self.wired("Lerax"):
with writing(0.1):
with writing(0.01):
print("I don't ever exists")
print("But I'm exists.")
print("hacking... hacking...")
Expand Down
48 changes: 48 additions & 0 deletions tests/test_monitor.py
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright © Manoel Vilela 2017
#
# @project: Decorating
# @author: Manoel Vilela
# @email: manoel_vilela@engineer.com
#

"""
These tests cover the basic usage of the decorator monitor_stdout
"""

import unittest
from decorating import monitor_stdout


class TestMonitorStdout(unittest.TestCase):

def test1(self):
"""Test using a context manager"""
test = "Cancer"
expected = ["Cancer", "\n"]
with monitor_stdout:
print(test)
self.assertListEqual(monitor_stdout.data, expected)

# TODO: fix this test!
# Description: this crash the decorating.decorator.Decorator.__call__
# procedure! Why???
# def test2(self):
# """Test using a function decorated"""
# monitor_stdout.clear()
# test = "This!"
# expected = ["This", "\n"]

# @monitor_stdout()
# def test():
# print(test)

# test()
# self.assertListEqual(monitor_stdout.data, expected)


if __name__ == '__main__':
unittest.main()

0 comments on commit ddf473d

Please sign in to comment.