-
Notifications
You must be signed in to change notification settings - Fork 222
Entry point to print test logs from JSON output. #684
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
Open
jeffherman
wants to merge
2
commits into
google:master
Choose a base branch
from
jeffherman:json-testcat
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,68 @@ | ||
# Copyright 2017 Google Inc. All Rights Reserved. | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Output a JSON-encoded log output to standard out. | ||
|
||
Takes OpenHTF JSON log outputs and prints out human-readable files. | ||
""" | ||
|
||
import argparse | ||
import datetime | ||
import json | ||
import logging | ||
|
||
|
||
ATTR_MAP = dict( | ||
red='\033[91m', | ||
green='\033[92m', | ||
yellow='\033[93m', | ||
blue='\033[94m', | ||
purple='\033[095m', | ||
cyan='\033[96m', | ||
white='\033[97m') | ||
|
||
LEVEL_MAP = { | ||
logging.DEBUG:'cyan', | ||
logging.INFO:'green', | ||
logging.WARNING:'yellow', | ||
logging.ERROR:'red', | ||
logging.CRITICAL:'red'} | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description=__doc__, | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
parser.add_argument( | ||
'test_json', help='Path of JSON to parse') | ||
options = parser.parse_args() | ||
|
||
test_output = json.load(open(options.test_json, 'r')) | ||
for log_record in test_output['log_records']: | ||
epoch = log_record['timestamp_millis'] / 1000. | ||
time_str = ( | ||
datetime.datetime.fromtimestamp(epoch).strftime( | ||
'%Y-%m-%d %H:%M:%S.%f')) | ||
attr = ATTR_MAP[LEVEL_MAP[log_record['level']]] | ||
for line in log_record['message'].splitlines(): | ||
print '{attr}{time_str} {source}:{lineno} {line}\033[0m'.format( | ||
attr=attr, | ||
time_str=time_str, | ||
source=log_record['source'], | ||
lineno=log_record['lineno'], | ||
line=line.encode('utf-8')) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be in
contrib/
orbin/
, notutil/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setuptools.find_packages
(used insetup.py
) will only search for directories with__init__.py
. Adding eithercontrib/
orbin/
to openhtf's package list will result in eithercontrib
orbin
being a top-level importable module. While it's unlikely that anyone would ever publish a bin or contrib pypi module, it's not clear that we should be co-opting this part of the namespace for openhtf-specific purposes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @jeffherman. Unless you want to force people to go to our GitHub page and download utilities separately, stuff like this should go somewhere inside the actual package.
However I am an advocate of using runnable modules (invoke with python -m) instead of declaring entry points for setuptools to wire up executable scripts. In my anecdotal experience, the entry points mechanism is more brittle and doesn't always work with all environments. Whereas if you've gotten as far as successfully making the packager itself importable, it's more unlikely runnable modules within will fail.