Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh-145 Add stats output block at the end of an update or import command.
- Loading branch information
Showing
5 changed files
with
115 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from tabulate import tabulate | ||
|
||
|
||
class Result(object): | ||
|
||
def __init__(self): | ||
self.records = [] | ||
self.success = 0 | ||
self.error = 0 | ||
self.error_items = [] | ||
|
||
def append(self, row): | ||
id, status = row | ||
|
||
if status: | ||
self.success += 1 | ||
else: | ||
self.error += 1 | ||
self.error_items.append(id) | ||
|
||
def write(self): | ||
if self.error > 0: | ||
error_headers = ["File"] | ||
error_result = [] | ||
for id in self.error_items: | ||
error_result.append([id]) | ||
|
||
print("****** ERROR DETAILS ******") | ||
print(tabulate(error_result, headers=error_headers)) | ||
print("\n") | ||
|
||
headers = ["Metric", "Count"] | ||
result = [ | ||
["Success", self.success], | ||
["Error", self.error], | ||
] | ||
|
||
print("****** SUMMARY ******") | ||
print(tabulate(result, headers=headers)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from __future__ import absolute_import | ||
# Project imports | ||
|
||
import os | ||
import sys | ||
import unittest | ||
|
||
from json import dumps | ||
from mock import patch | ||
try: | ||
from StringIO import StringIO | ||
except ImportError: | ||
from io import StringIO | ||
|
||
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))) | ||
|
||
from elodie import constants | ||
from elodie.result import Result | ||
|
||
def call_result_and_assert(result, expected): | ||
saved_stdout = sys.stdout | ||
try: | ||
out = StringIO() | ||
sys.stdout = out | ||
result.write() | ||
output = out.getvalue().strip() | ||
assert output == expected, expected | ||
finally: | ||
sys.stdout = saved_stdout | ||
|
||
def test_add_multiple_rows(): | ||
expected = """****** ERROR DETAILS ****** | ||
File | ||
------ | ||
id1 | ||
****** SUMMARY ****** | ||
Metric Count | ||
-------- ------- | ||
Success 1 | ||
Error 1""" | ||
result = Result() | ||
result.append(('id1', None)) | ||
result.append(('id2', '/some/path')) | ||
call_result_and_assert(result, expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ requests==2.11.1 | |
Send2Trash==1.3.0 | ||
future==0.16.0 | ||
configparser==3.5.0 | ||
tabulate==0.7.7 |