Skip to content
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

Migrate CLX parsers #894

Merged
merged 16 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
style fixes
  • Loading branch information
efajardo-nv committed Apr 27, 2023
commit 03256b4fac6759f1cf1906ad1e897c711ef11b71
2 changes: 1 addition & 1 deletion morpheus/parsers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
250 changes: 122 additions & 128 deletions tests/test_url_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,155 +13,149 @@
# limitations under the License.

import pytest

from cudf import DataFrame

from morpheus.parsers import url_parser

input_df = DataFrame(
{
"url": [
"http://www.google.com",
"gmail.com",
"github.com",
"https://pandas.pydata.org",
"http://www.worldbank.org.kg/",
"waiterrant.blogspot.com",
"http://forums.news.cnn.com.ac/",
"http://forums.news.cnn.ac/",
"ftp://b.cnn.com/",
"a.news.uk",
"a.news.co.uk",
"https://a.news.co.uk",
"107-193-100-2.lightspeed.cicril.sbcglobal.net",
"a23-44-13-2.deploy.static.akamaitechnologies.com",
]
}
)
input_df = DataFrame({
"url": [
"http://www.google.com",
"gmail.com",
"github.com",
"https://pandas.pydata.org",
"http://www.worldbank.org.kg/",
"waiterrant.blogspot.com",
"http://forums.news.cnn.com.ac/",
"http://forums.news.cnn.ac/",
"ftp://b.cnn.com/",
"a.news.uk",
"a.news.co.uk",
"https://a.news.co.uk",
"107-193-100-2.lightspeed.cicril.sbcglobal.net",
"a23-44-13-2.deploy.static.akamaitechnologies.com",
]
})


@pytest.mark.parametrize("input_df", [input_df])
def test_parse_1(input_df):
expected_output_df = DataFrame(
{
"domain": [
"google",
"gmail",
"github",
"pydata",
"worldbank",
"waiterrant",
"cnn",
"cnn",
"cnn",
"news",
"news",
"news",
"sbcglobal",
"akamaitechnologies",
],
"suffix": [
"com",
"com",
"com",
"org",
"org.kg",
"blogspot.com",
"com.ac",
"ac",
"com",
"uk",
"co.uk",
"co.uk",
"net",
"com",
],
}
)
expected_output_df = DataFrame({
"domain": [
"google",
"gmail",
"github",
"pydata",
"worldbank",
"waiterrant",
"cnn",
"cnn",
"cnn",
"news",
"news",
"news",
"sbcglobal",
"akamaitechnologies",
],
"suffix": [
"com",
"com",
"com",
"org",
"org.kg",
"blogspot.com",
"com.ac",
"ac",
"com",
"uk",
"co.uk",
"co.uk",
"net",
"com",
],
})
output_df = url_parser.parse(input_df["url"], req_cols={"domain", "suffix"})

assert expected_output_df.equals(output_df)


@pytest.mark.parametrize("input_df", [input_df])
def test_parse_2(input_df):
expected_output_df = DataFrame(
{
"hostname": [
"www.google.com",
"gmail.com",
"github.com",
"pandas.pydata.org",
"www.worldbank.org.kg",
"waiterrant.blogspot.com",
"forums.news.cnn.com.ac",
"forums.news.cnn.ac",
"b.cnn.com",
"a.news.uk",
"a.news.co.uk",
"a.news.co.uk",
"107-193-100-2.lightspeed.cicril.sbcglobal.net",
"a23-44-13-2.deploy.static.akamaitechnologies.com",
],
"subdomain": [
"www",
"",
"",
"pandas",
"www",
"",
"forums.news",
"forums.news",
"b",
"a",
"a",
"a",
"107-193-100-2.lightspeed.cicril",
"a23-44-13-2.deploy.static",
],
"domain": [
"google",
"gmail",
"github",
"pydata",
"worldbank",
"waiterrant",
"cnn",
"cnn",
"cnn",
"news",
"news",
"news",
"sbcglobal",
"akamaitechnologies",
],
"suffix": [
"com",
"com",
"com",
"org",
"org.kg",
"blogspot.com",
"com.ac",
"ac",
"com",
"uk",
"co.uk",
"co.uk",
"net",
"com",
],
}
)
expected_output_df = DataFrame({
"hostname": [
"www.google.com",
"gmail.com",
"github.com",
"pandas.pydata.org",
"www.worldbank.org.kg",
"waiterrant.blogspot.com",
"forums.news.cnn.com.ac",
"forums.news.cnn.ac",
"b.cnn.com",
"a.news.uk",
"a.news.co.uk",
"a.news.co.uk",
"107-193-100-2.lightspeed.cicril.sbcglobal.net",
"a23-44-13-2.deploy.static.akamaitechnologies.com",
],
"subdomain": [
"www",
"",
"",
"pandas",
"www",
"",
"forums.news",
"forums.news",
"b",
"a",
"a",
"a",
"107-193-100-2.lightspeed.cicril",
"a23-44-13-2.deploy.static",
],
"domain": [
"google",
"gmail",
"github",
"pydata",
"worldbank",
"waiterrant",
"cnn",
"cnn",
"cnn",
"news",
"news",
"news",
"sbcglobal",
"akamaitechnologies",
],
"suffix": [
"com",
"com",
"com",
"org",
"org.kg",
"blogspot.com",
"com.ac",
"ac",
"com",
"uk",
"co.uk",
"co.uk",
"net",
"com",
],
})
output_df = url_parser.parse(input_df["url"])

assert expected_output_df.equals(output_df)


@pytest.mark.parametrize("input_df", [input_df])
def test_parse_invalid_req_cols(input_df):
expected_error = ValueError(
"Given req_cols must be subset of %s"
% ('["hostname", "subdomain", "domain", "suffix"]')
)
expected_error = ValueError("Given req_cols must be subset of %s" %
('["hostname", "subdomain", "domain", "suffix"]'))
with pytest.raises(ValueError) as actual_error:
url_parser.parse(input_df["url"], req_cols={"test"})
assert actual_error == expected_error