-
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.
Decoupling tests from analyze_log_stream (#67)
* fixing error counter test * fixing duplicate counter test * fixing warning counter test * un-commenting analyze_log_stream test
- Loading branch information
Showing
5 changed files
with
47 additions
and
29 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
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 |
---|---|---|
@@ -1,19 +1,27 @@ | ||
import io | ||
|
||
from alogamous import analyzer, flag_duplicate_log_messages | ||
from alogamous import flag_duplicate_log_messages | ||
|
||
|
||
def test_flag_duplicate_log_messages(): | ||
flagger = flag_duplicate_log_messages.FlagDuplicateLogMessages() | ||
in_stream = io.StringIO("""Date - root - INFO - log message 1 | ||
Date - root - WARNING - log message 2 | ||
Date - root - WARNING - log message 1""") | ||
out_stream = io.StringIO() | ||
analyzer.analyze_log_stream([flag_duplicate_log_messages.FlagDuplicateLogMessages()], in_stream, out_stream) | ||
for line in in_stream: | ||
flagger.read_log_line(line) | ||
flagger.report(out_stream) | ||
assert out_stream.getvalue() == """Duplicate Log Messages:\nlog message 1\n""" | ||
|
||
|
||
def test_flag_duplicate_log_messages_no_duplicates(): | ||
flagger = flag_duplicate_log_messages.FlagDuplicateLogMessages() | ||
in_stream = io.StringIO("""Date - root - INFO - log message 1 | ||
Date - root - WARNING - log message 2 | ||
Date - root - WARNING - log message 3""") | ||
out_stream = io.StringIO() | ||
analyzer.analyze_log_stream([flag_duplicate_log_messages.FlagDuplicateLogMessages()], in_stream, out_stream) | ||
for line in in_stream: | ||
flagger.read_log_line(line) | ||
flagger.report(out_stream) | ||
assert out_stream.getvalue() == """No duplicate log messages\n""" |
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 |
---|---|---|
@@ -1,29 +1,34 @@ | ||
import io | ||
|
||
from alogamous import analyzer, error_counter_analyzer | ||
from alogamous import error_counter_analyzer | ||
|
||
|
||
def test_error_counter(): | ||
in_stream = io.StringIO("""line1 | ||
blahblahERRORblah | ||
oh_no_another_ERROR""") | ||
counter = error_counter_analyzer.ErrorCounterAnalyzer() | ||
in_stream = io.StringIO( | ||
"""2024-06-20 17:16:03,660 - root - ERROR - Caught exception N/A. | ||
2024-06-20 17:16:03,660 - root - ERROR - Caught exception N/A. Message: Unclosed connector NoneType: None""" | ||
) | ||
out_stream = io.StringIO() | ||
analyzer.analyze_log_stream([error_counter_analyzer.ErrorCounterAnalyzer()], in_stream, out_stream) | ||
for line in in_stream: | ||
counter.read_log_line(line) | ||
counter.report(out_stream) | ||
assert out_stream.getvalue().strip() == "Number of error lines: 2" | ||
|
||
|
||
def test_no_errors(): | ||
in_stream = io.StringIO("""good | ||
nice | ||
very good | ||
""") | ||
counter = error_counter_analyzer.ErrorCounterAnalyzer() | ||
in_stream = io.StringIO("""2024-06-20 17:17:04,278 - root - INFO - Updating prices | ||
2024-06-20 17:24:34,091 - root - INFO - Closing client connection.""") | ||
out_stream = io.StringIO() | ||
analyzer.analyze_log_stream([error_counter_analyzer.ErrorCounterAnalyzer()], in_stream, out_stream) | ||
for line in in_stream: | ||
counter.read_log_line(line) | ||
counter.report(out_stream) | ||
assert out_stream.getvalue().strip() == "Number of error lines: 0" | ||
|
||
|
||
def test_no_input_lines(): | ||
in_stream = io.StringIO("") | ||
counter = error_counter_analyzer.ErrorCounterAnalyzer() | ||
out_stream = io.StringIO() | ||
analyzer.analyze_log_stream([error_counter_analyzer.ErrorCounterAnalyzer()], in_stream, out_stream) | ||
counter.report(out_stream) | ||
assert out_stream.getvalue().strip() == "Number of error lines: 0" |
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