-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding Analyzer class and main function * Adding EchoAnalyzer * Adding abstractmethod annotation to Analyzer methods --------- Co-authored-by: Ben Rady <[email protected]>
- Loading branch information
1 parent
02dd315
commit 6f23a38
Showing
6 changed files
with
53 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import sys | ||
|
||
from alogamous import analyzer, echo_analyzer | ||
|
||
analyzer.analyze_log_stream([echo_analyzer.EchoAnalyzer()], sys.stdin, sys.stdout) |
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,19 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class Analyzer(ABC): | ||
@abstractmethod | ||
def read_log_line(self, line): | ||
pass | ||
|
||
@abstractmethod | ||
def report(self, out_stream): | ||
pass | ||
|
||
|
||
def analyze_log_stream(analyzers, in_stream, out_stream): | ||
for line in in_stream: | ||
for analyzer in analyzers: | ||
analyzer.read_log_line(line.rstrip()) | ||
for analyzer in analyzers: | ||
analyzer.report(out_stream) |
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,12 @@ | ||
from alogamous import analyzer | ||
|
||
|
||
class EchoAnalyzer(analyzer.Analyzer): | ||
def __init__(self): | ||
self.lines = [] | ||
|
||
def read_log_line(self, line): | ||
self.lines.append(line) | ||
|
||
def report(self, out_stream): | ||
out_stream.write("\n".join(self.lines)) |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
import io | ||
|
||
from alogamous import analyzer, echo_analyzer | ||
|
||
|
||
def test_echo_lines(): | ||
in_stream = io.StringIO("""line1 | ||
line2 | ||
line3""") | ||
out_stream = io.StringIO() | ||
analyzer.analyze_log_stream([echo_analyzer.EchoAnalyzer()], in_stream, out_stream) | ||
assert ( | ||
out_stream.getvalue() | ||
== """line1 | ||
line2 | ||
line3""" | ||
) |
This file was deleted.
Oops, something went wrong.