This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from target/dev
Merge dev to master
- Loading branch information
Showing
7 changed files
with
181 additions
and
5 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
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,25 @@ | ||
#!/usr/bin/env python | ||
|
||
from huntlib.data import chunk | ||
import numpy as np | ||
|
||
from unittest import TestCase | ||
|
||
class TestChunk(TestCase): | ||
def test_chunk(self): | ||
l = list(np.random.randint(10, size=100)) | ||
|
||
res = list(chunk(l)) | ||
|
||
# There should be 10 equal chunks with the default chunk size | ||
self.assertEqual(len(res), 10) | ||
|
||
# All chunks should be size 10 | ||
self.assertEqual(len(res[0]), 10) | ||
|
||
# Rechunk with an odd size that won't result in equal chunks | ||
res = list(chunk(l, size=9)) | ||
|
||
self.assertEqual(len(res), 12) | ||
self.assertEqual(len(res[0]), 9) | ||
self.assertEqual(len(res[-1]), 1) |
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,54 @@ | ||
#!/usr/bin/env python | ||
|
||
from huntlib.util import punctuation_pattern | ||
import pandas as pd | ||
import numpy as np | ||
|
||
from unittest import TestCase | ||
|
||
class TestPunctuationPattern(TestCase): | ||
_event_message_1 = '192.168.1.1 - - [10/Oct/2020:12:32:27 +0000] "GET /some/web/app?param=test¶m2=another_test" 200 9987' | ||
_event_message_2 = 'ERROR: Can\'t resolve "nosuchhost": No such host.' | ||
_punct_pattern_1 = '..._-_-_[//:::_+]_\"_///?=&=_\"__' | ||
_punct_pattern_2 = ':_\'__\"\":___.' | ||
|
||
_expected_pattern_result = pd.Series([_punct_pattern_1, _punct_pattern_2]) | ||
|
||
def test_punctuation_pattern_single_string(self): | ||
res = punctuation_pattern(self._event_message_1) | ||
|
||
self.assertEqual(res, self._punct_pattern_1) | ||
|
||
def test_punctuation_pattern_list(self): | ||
res = punctuation_pattern( | ||
[ | ||
self._event_message_1, | ||
self._event_message_2 | ||
] | ||
) | ||
|
||
self.assertListEqual(list(res), list(self._expected_pattern_result)) | ||
|
||
def test_punctuation_pattern_series(self): | ||
res = punctuation_pattern( | ||
pd.Series( | ||
[ | ||
self._event_message_1, | ||
self._event_message_2 | ||
] | ||
) | ||
) | ||
|
||
self.assertListEqual(list(res), list(self._expected_pattern_result)) | ||
|
||
def test_punctuation_pattern_escape_quotes(self): | ||
res = punctuation_pattern("\'\"") | ||
self.assertEqual(res, '\'\"') | ||
|
||
res = punctuation_pattern("\'\"", escape_quotes=False) | ||
self.assertEqual(res, '\'\"') | ||
|
||
res = punctuation_pattern("\'\"", escape_quotes=True) | ||
self.assertEqual(res, '\\\'\\\"') | ||
|
||
|