repo_id stringclasses 409
values | prefix large_stringlengths 34 36.3k | target large_stringlengths 1 498 | assertion_type stringclasses 31
values | difficulty stringclasses 8
values | test_file stringlengths 10 121 | test_function stringlengths 1 104 | test_class stringlengths 0 51 | lineno int32 2 11.3k | commit_idx int32 |
|---|---|---|---|---|---|---|---|---|---|
shakedzy/dython | import pytest
import numpy as np
from dython.model_utils import _binary_ks_curve
def test_binary_ks_curve_multiclass_error():
"""Test binary_ks_curve with more than 2 classes"""
y_true = np.array([0, 1, 2, 0, 1, 2])
y_probas = np.array([0.1, 0.5, 0.9, 0.2, 0.6, 0.8])
with pytest.raises( | ValueError) | pytest.raises | variable | tests/test_model_utils/test_binary_ks_curve.py | test_binary_ks_curve_multiclass_error | 25 | null | |
shakedzy/dython | import pytest
from hypothesis import given, strategies as st
from dython.nominal import theils_u
def test_theils_u_check(iris_df):
x = iris_df["extra"]
y = iris_df["target"]
# Note: this measure is not symmetric
assert theils_u(x, y) == pytest.approx( | 0.02907500150218738) | pytest.approx | numeric_literal | tests/test_nominal/test_theils_u.py | test_theils_u_check | 12 | null | |
shakedzy/dython | import pytest
import pandas as pd
import numpy as np
import scipy.stats as ss
from sklearn import datasets
from datetime import datetime, timedelta
from matplotlib.axes._axes import Axes
from dython.nominal import associations, correlation_ratio
def test_bad_nom_nom_assoc_parameter(iris_df):
with pytest.raises( | ValueError, match="is not a supported") | pytest.raises | complex_expr | tests/test_nominal/test_associations.py | test_bad_nom_nom_assoc_parameter | 57 | null | |
shakedzy/dython | import pytest
import functools
import numpy as np
from hypothesis import given, strategies as st, assume, settings
from dython.nominal import cramers_v
approx = functools.partial(pytest.approx, abs=1e-6, rel=1e-6)
def two_categorical_lists(draw):
n = draw(st.integers(min_value=2, max_value=30))
categorical_l... | approx(v_yx) | assert | func_call | tests/test_nominal/test_cramers_v.py | test_cramers_v_symmetry | 61 | null | |
shakedzy/dython | import pytest
import numpy as np
import pandas as pd
from sklearn import datasets
from dython._private import (
convert,
remove_incomplete_samples,
replace_nan_with_value,
)
pd.set_option("mode.chained_assignment", None)
def iris_df():
iris = datasets.load_iris()
df = pd.DataFrame(data=iris.data, ... | y_[1] | assert | complex_expr | tests/test_private_helpers.py | test_replace_nan_one_nan_each | 83 | null | |
shakedzy/dython | import pytest
import functools
import numpy as np
from hypothesis import given, strategies as st, assume, settings
from dython.nominal import cramers_v
approx = functools.partial(pytest.approx, abs=1e-6, rel=1e-6)
def two_categorical_lists(draw):
n = draw(st.integers(min_value=2, max_value=30))
categorical_l... | 0.0) | pytest.approx | numeric_literal | tests/test_nominal/test_cramers_v.py | test_cramers_v_value_range | 44 | null | |
shakedzy/dython | import pytest
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.axes._axes import Axes
from dython.data_utils import split_hist
class TestSplitHistAdvanced:
def test_split_hist_with_ylabel(self, iris_df):
"""Test split_hist with ylabel (covers line 121-122)"""
... | "Frequency" | assert | string_literal | tests/test_data_utils/test_split_hist_advanced.py | test_split_hist_with_ylabel | TestSplitHistAdvanced | 109 | null |
shakedzy/dython | import pytest
import numpy as np
from dython.model_utils import _binary_ks_curve
def test_binary_ks_curve_basic():
"""Test basic binary_ks_curve functionality"""
y_true = np.array([0, 1, 0, 1, 1, 0])
y_probas = np.array([0.1, 0.9, 0.3, 0.8, 0.7, 0.2])
thresholds, pct1, pct2, ks_stat, max_dist, cla... | 0 | assert | numeric_literal | tests/test_model_utils/test_binary_ks_curve.py | test_binary_ks_curve_basic | 13 | null | |
shakedzy/dython | import pytest
import numpy as np
import pandas as pd
from dython.nominal import numerical_encoding
def test_numerical_encoding_with_nan_drop_samples():
"""Test numerical encoding with nan drop_samples strategy"""
df = pd.DataFrame({
'cat1': ['a', 'b', None, 'a'],
'num': [1, 2, 3, 4]
})
... | len(df) | assert | func_call | tests/test_nominal/test_numerical_encoding.py | test_numerical_encoding_with_nan_drop_samples | 108 | null | |
shakedzy/dython | import pytest
import numpy as np
from matplotlib.axes._axes import Axes
from dython.model_utils import ks_abc
def y_true():
return np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1])
def y_pred():
return np.array([0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])
def test_ks_abc_check_types(y_true, y_pred):
... | result | assert | variable | tests/test_model_utils/test_ks_abc.py | test_ks_abc_check_types | 22 | null | |
shakedzy/dython | import pytest
import pandas as pd
import numpy as np
import scipy.stats as ss
from sklearn import datasets
from datetime import datetime, timedelta
from matplotlib.axes._axes import Axes
from dython.nominal import associations, correlation_ratio
def test_dimension_check(iris_df):
corr = associations(iris_df)["cor... | iris_shape[1] | assert | complex_expr | tests/test_nominal/test_associations.py | test_dimension_check | 37 | null | |
shakedzy/dython | import pytest
import numpy as np
import pandas as pd
from dython.nominal import numerical_encoding
def test_numerical_encoding_two_values():
"""Test numerical encoding with exactly two values (factorize)"""
df = pd.DataFrame({
'cat1': ['a', 'b', 'a', 'b'],
'num': [1, 2, 3, 4]
})
result,... | fact_dict | assert | variable | tests/test_nominal/test_numerical_encoding.py | test_numerical_encoding_two_values | 143 | null | |
shakedzy/dython | import pytest
import functools
import numpy as np
from hypothesis import given, strategies as st, assume, settings
from dython.nominal import cramers_v
approx = functools.partial(pytest.approx, abs=1e-6, rel=1e-6)
def test_cramers_v_check(iris_df):
x = iris_df["extra"]
y = iris_df["target"]
# Note: this... | pytest.approx(0.14201914309546954) | assert | func_call | tests/test_nominal/test_cramers_v.py | test_cramers_v_check | 18 | null | |
shakedzy/dython | import pytest
import numpy as np
import pandas as pd
from dython.data_utils import identify_columns_by_type, identify_columns_with_na
class TestIdentifyColumnsWithNA:
def test_identify_columns_with_na_no_na(self):
"""Test when no columns have NA values"""
df = pd.DataFrame({
'col1': [1... | 0 | assert | numeric_literal | tests/test_data_utils/test_identify_columns.py | test_identify_columns_with_na_no_na | TestIdentifyColumnsWithNA | 156 | null |
shakedzy/dython | import pytest
import numpy as np
from dython.model_utils import _binary_ks_curve
def test_binary_ks_curve_basic():
"""Test basic binary_ks_curve functionality"""
y_true = np.array([0, 1, 0, 1, 1, 0])
y_probas = np.array([0.1, 0.9, 0.3, 0.8, 0.7, 0.2])
thresholds, pct1, pct2, ks_stat, max_dist, cla... | 2 | assert | numeric_literal | tests/test_model_utils/test_binary_ks_curve.py | test_binary_ks_curve_basic | 17 | null | |
shakedzy/dython | import pytest
import pandas as pd
import numpy as np
import scipy.stats as ss
from sklearn import datasets
from datetime import datetime, timedelta
from matplotlib.axes._axes import Axes
from dython.nominal import associations, correlation_ratio
def test_return_type_check(iris_df):
assoc = associations(iris_df)
... | assoc | assert | variable | tests/test_nominal/test_associations.py | test_return_type_check | 16 | null | |
shakedzy/dython | import pytest
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.axes._axes import Axes
from dython.data_utils import split_hist
class TestSplitHistAdvanced:
def test_split_hist_with_custom_title(self, iris_df):
"""Test split_hist with custom title"""
result = s... | "Custom Title" | assert | string_literal | tests/test_data_utils/test_split_hist_advanced.py | test_split_hist_with_custom_title | TestSplitHistAdvanced | 23 | null |
shakedzy/dython | import pytest
import numpy as np
import pandas as pd
from dython.data_utils import identify_columns_by_type, identify_columns_with_na
class TestIdentifyColumnsByType:
def test_identify_int_columns(self):
"""Test identifying integer columns"""
df = pd.DataFrame({
'int_col': [1, 2, 3, 4]... | result | assert | variable | tests/test_data_utils/test_identify_columns.py | test_identify_int_columns | TestIdentifyColumnsByType | 19 | null |
shakedzy/dython | import pytest
import pandas as pd
import scipy.stats as ss
import numpy as np
from psutil import cpu_count
from datetime import datetime, timedelta
from matplotlib.axes._axes import Axes
from dython.nominal import associations, correlation_ratio
MAX_CORE_COUNT = cpu_count(logical=False)
def test_dimension_check(iris... | iris_shape[1] | assert | complex_expr | tests/test_nominal/test_associations_parallel.py | test_dimension_check | 43 | null | |
shakedzy/dython | import pytest
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from dython._private import (
convert,
remove_incomplete_samples,
replace_nan_with_value,
plot_or_not,
set_is_jupyter,
)
class TestRemoveIncompleteSamplesAdditional:
def test_remove_incomplete_samples_no_nans(... | 5 | assert | numeric_literal | tests/test_private_helpers_advanced.py | test_remove_incomplete_samples_no_nans | TestRemoveIncompleteSamplesAdditional | 143 | null |
shakedzy/dython | import pytest
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.axes._axes import Axes
from dython.data_utils import split_hist
class TestSplitHistAdvanced:
def test_split_hist_with_default_xlabel(self, iris_df):
"""Test split_hist with default xlabel (empty string)"""... | "sepal length (cm)" | assert | string_literal | tests/test_data_utils/test_split_hist_advanced.py | test_split_hist_with_default_xlabel | TestSplitHistAdvanced | 81 | null |
shakedzy/dython | import pytest
import numpy as np
import pandas as pd
from dython.nominal import conditional_entropy
def test_conditional_entropy_basic():
"""Test basic conditional entropy calculation"""
x = [1, 1, 2, 2, 3, 3]
y = ['a', 'a', 'b', 'b', 'c', 'c']
result = conditional_entropy(x, y)
assert isinstance(r... | 0 | assert | numeric_literal | tests/test_nominal/test_conditional_entropy.py | test_conditional_entropy_basic | 13 | null | |
shakedzy/dython | import pytest
import numpy as np
import pandas as pd
from sklearn import datasets
from dython._private import (
convert,
remove_incomplete_samples,
replace_nan_with_value,
)
pd.set_option("mode.chained_assignment", None)
def iris_df():
iris = datasets.load_iris()
df = pd.DataFrame(data=iris.data, ... | TypeError, match="cannot handle data conversion") | pytest.raises | complex_expr | tests/test_private_helpers.py | test_convert_good_output_bad_input | 41 | null | |
shakedzy/dython | import pytest
from hypothesis import given, strategies as st
from dython.nominal import theils_u
def test_theils_u_check(iris_df):
x = iris_df["extra"]
y = iris_df["target"]
# Note: this measure is not symmetric
assert theils_u(x, y) == pytest.approx(0.02907500150218738)
assert theils_u(y, x) ==... | 0.0424761859049835) | pytest.approx | numeric_literal | tests/test_nominal/test_theils_u.py | test_theils_u_check | 13 | null | |
shakedzy/dython | import pytest
import numpy as np
import pandas as pd
from dython.nominal import associations, theils_u, correlation_ratio, cramers_v
def test_theils_u_single_category():
"""Test Theil's U with single category returns 1"""
# When x and y are completely determined by each other
x = ['a'] * 100
y = ['a'] ... | 1.0 | assert | numeric_literal | tests/test_nominal/test_inf_nan_handling.py | test_theils_u_single_category | 14 | null | |
shakedzy/dython | import pytest
import numpy as np
import pandas as pd
from dython.data_utils import identify_columns_by_type, identify_columns_with_na
class TestIdentifyColumnsWithNA:
def test_identify_columns_with_na_basic(self):
"""Test basic identification of columns with NA values"""
df = pd.DataFrame({
... | 2 | assert | numeric_literal | tests/test_data_utils/test_identify_columns.py | test_identify_columns_with_na_basic | TestIdentifyColumnsWithNA | 125 | null |
shakedzy/dython | import pytest
import numpy as np
import pandas as pd
from dython.data_utils import identify_columns_by_type, identify_columns_with_na
class TestIdentifyColumnsByType:
def test_identify_all_columns_match(self):
"""Test when all columns match the requested type"""
df = pd.DataFrame({
'co... | 3 | assert | numeric_literal | tests/test_data_utils/test_identify_columns.py | test_identify_all_columns_match | TestIdentifyColumnsByType | 100 | null |
shakedzy/dython | import pytest
import pandas as pd
import scipy.stats as ss
import numpy as np
from psutil import cpu_count
from datetime import datetime, timedelta
from matplotlib.axes._axes import Axes
from dython.nominal import associations, correlation_ratio
MAX_CORE_COUNT = cpu_count(logical=False)
def test_mark_columns(iris_df... | corr.index[0] | assert | complex_expr | tests/test_nominal/test_associations_parallel.py | test_mark_columns | 100 | null | |
ktbyers/netmiko | import pytest
import time
from datetime import datetime
from netmiko import ConnectHandler
def test_send_command_timing(net_connect, commands, expected_responses):
"""Verify a command can be sent down the channel successfully."""
time.sleep(1)
net_connect.clear_buffer()
# Force verification of command ... | show_ip | assert | variable | tests/test_netmiko_show.py | test_send_command_timing | 81 | null | |
ktbyers/netmiko | from datetime import datetime
def execute_cmd(conn, cmd="show tech-support", read_timeout=None, last_read=2.0):
start_time = datetime.now()
cmd = cmd.strip()
conn.write_channel(cmd + "\n")
if read_timeout is None:
output = conn.read_channel_timing(last_read=last_read)
else:
output =... | 90 | assert | numeric_literal | tests/test_timeout_read_timing.py | test_read_traceroute_no_response_full | 108 | null | |
ktbyers/netmiko | import pytest
import time
from os.path import dirname, join
from threading import Lock
import paramiko
from netmiko import NetmikoTimeoutException, log, ConnectHandler
from netmiko.base_connection import BaseConnection
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
def test_use_ssh_file():
"""Update S... | result | assert | variable | tests/unit/test_base_connection.py | test_use_ssh_file | 87 | null | |
ktbyers/netmiko | import pytest
import time
from datetime import datetime
from netmiko import ConnectHandler
def test_ssh_connect_cm(net_connect_cm, net_connect, commands, expected_responses):
"""Test the context manager."""
if net_connect.device_type == "audiocode_shell":
assert pytest.skip("Disable Paging not supporte... | prompt_str | assert | variable | tests/test_netmiko_show.py | test_ssh_connect_cm | 72 | null | |
ktbyers/netmiko | import sys
import pytest
import logging
from netmiko import ConnectHandler, ConnLogOnly, ConnUnify
from netmiko import NetmikoAuthenticationException
from netmiko import NetmikoTimeoutException
from netmiko import ConnectionException
is_linux = sys.platform == "linux" or sys.platform == "linux2"
skip_if_not_linux = py... | ConnectionException) | pytest.raises | variable | tests/unit/test_connection.py | test_connunify | 54 | null | |
ktbyers/netmiko | import os
import sys
from os.path import dirname, join, relpath
import pytest
from netmiko import utilities
from textfsm import clitable
from netmiko.exceptions import NetmikoParsingException
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
RELATIVE_RESOURCE_FOLDER = join(dirname(dirname(relpath(__file__)))... | ValueError) | pytest.raises | variable | tests/unit/test_utilities.py | test_ntc_templates_discovery | 336 | null | |
ktbyers/netmiko | def test_remote_file_size(tcl_fixture):
ssh_conn, transfer = tcl_fixture
remote_file_size = transfer.remote_file_size()
assert remote_file_size == | 20 | assert | numeric_literal | tests/test_netmiko_tcl.py | test_remote_file_size | 30 | null | |
ktbyers/netmiko | import os
import sys
from os.path import dirname, join, relpath
import pytest
from netmiko import utilities
from textfsm import clitable
from netmiko.exceptions import NetmikoParsingException
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
RELATIVE_RESOURCE_FOLDER = join(dirname(dirname(relpath(__file__)))... | folder | assert | variable | tests/unit/test_utilities.py | test_find_netmiko_dir | 217 | null | |
ktbyers/netmiko | import time
import re
import random
import string
import pytest
def gen_random(N=6):
return "".join(
[
random.choice(
string.ascii_lowercase + string.ascii_uppercase + string.digits
)
for x in range(N)
]
)
def retrieve_commands(commands):
... | response_label | assert | variable | tests/test_netmiko_commit.py | test_commit_label | 335 | null | |
ktbyers/netmiko | from pathlib import Path
import pytest
from unittest.mock import patch, MagicMock
from netmiko.cli_tools import ERROR_PATTERN
from netmiko.cli_tools.helpers import ssh_conn, obtain_devices, update_device_params
BASE_YAML_PATH = Path(__file__).parent / "NETMIKO_YAML"
def mock_connecthandler():
with patch("netmiko... | initial_params | assert | variable | tests/unit/test_clitools_helpers.py | test_update_device_params | 128 | null | |
ktbyers/netmiko | import pytest
import time
from datetime import datetime
from netmiko import ConnectHandler
def test_clear_buffer(net_connect, commands, expected_responses):
"""Test that clearing the buffer works."""
# x!@#!# Mikrotik
enter = net_connect.RETURN
# Manually send a command down the channel so that data n... | "" | assert | string_literal | tests/test_netmiko_show.py | test_clear_buffer | 358 | null | |
ktbyers/netmiko | import os
import sys
from os.path import dirname, join, relpath
import pytest
from netmiko import utilities
from textfsm import clitable
from netmiko.exceptions import NetmikoParsingException
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
RELATIVE_RESOURCE_FOLDER = join(dirname(dirname(relpath(__file__)))... | "" | assert | string_literal | tests/unit/test_utilities.py | test_nokia_context_filter | 551 | null | |
ktbyers/netmiko | import pytest
import time
from datetime import datetime
from netmiko import ConnectHandler
def test_send_multiline_prompt(net_connect):
"""Use send_multiline, but use device's prompt as expect_string"""
debug = False
if (
"cisco_ios" not in net_connect.device_type
and "cisco_xe" not in net... | output | assert | variable | tests/test_netmiko_show.py | test_send_multiline_prompt | 280 | null | |
ktbyers/netmiko | import sys
import pytest
import logging
from netmiko import ConnectHandler, ConnLogOnly, ConnUnify
from netmiko import NetmikoAuthenticationException
from netmiko import NetmikoTimeoutException
from netmiko import ConnectionException
is_linux = sys.platform == "linux" or sys.platform == "linux2"
skip_if_not_linux = py... | NetmikoAuthenticationException) | pytest.raises | variable | tests/unit/test_connection.py | test_connecthandler_auth_failure | 32 | null | |
ktbyers/netmiko | from datetime import datetime
def execute_cmd(conn, cmd="show tech-support", read_timeout=None, last_read=2.0):
start_time = datetime.now()
cmd = cmd.strip()
conn.write_channel(cmd + "\n")
if read_timeout is None:
output = conn.read_channel_timing(last_read=last_read)
else:
output =... | 10 | assert | numeric_literal | tests/test_timeout_read_timing.py | test_read_show_tech | 42 | null | |
ktbyers/netmiko | import re
import pytest
from netmiko import ConfigInvalidException
from netmiko import ReadTimeout
def test_config_error_pattern(net_connect, commands, expected_responses):
"""
Raise exception when config_error_str is present in output
"""
error_pattern = commands.get("error_pattern")
if error_patt... | ConfigInvalidException) | pytest.raises | variable | tests/test_netmiko_config.py | test_config_error_pattern | 184 | null | |
ktbyers/netmiko | from os import path
from datetime import datetime
import pytest
from netmiko import ConnectHandler
from netmiko import NetmikoTimeoutException
from test_utils import parse_yaml
PWD = path.dirname(path.realpath(__file__))
DEVICE_DICT = parse_yaml(PWD + "/etc/test_devices_exc.yml")
def test_dns_fail_timeout():
"""S... | 0.1 | assert | numeric_literal | tests/test_netmiko_exceptions.py | test_dns_fail_timeout | 64 | null | |
ktbyers/netmiko | import pytest
import time
from os.path import dirname, join
from threading import Lock
import paramiko
from netmiko import NetmikoTimeoutException, log, ConnectHandler
from netmiko.base_connection import BaseConnection
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
def lock_unlock_timeout(timeout=0):
... | "\n\n\n" | assert | string_literal | tests/unit/test_base_connection.py | test_strip_ansi_codes | 484 | null | |
ktbyers/netmiko | import pytest
import time
from os.path import dirname, join
from threading import Lock
import paramiko
from netmiko import NetmikoTimeoutException, log, ConnectHandler
from netmiko.base_connection import BaseConnection
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
def test_select_global_delay_factor():
... | 4 | assert | numeric_literal | tests/unit/test_base_connection.py | test_select_global_delay_factor | 255 | null | |
ktbyers/netmiko | import pytest
import time
from os.path import dirname, join
from threading import Lock
import paramiko
from netmiko import NetmikoTimeoutException, log, ConnectHandler
from netmiko.base_connection import BaseConnection
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
def test_use_ssh_file():
"""Update S... | expected | assert | variable | tests/unit/test_base_connection.py | test_use_ssh_file | 91 | null | |
ktbyers/netmiko | import sys
import pytest
import logging
from netmiko import ConnectHandler, ConnLogOnly, ConnUnify
from netmiko import NetmikoAuthenticationException
from netmiko import NetmikoTimeoutException
from netmiko import ConnectionException
is_linux = sys.platform == "linux" or sys.platform == "linux2"
skip_if_not_linux = py... | None | assert | none_literal | tests/unit/test_connection.py | test_connlogonly | 46 | null | |
ktbyers/netmiko | import os
import sys
from os.path import dirname, join, relpath
import pytest
from netmiko import utilities
from textfsm import clitable
from netmiko.exceptions import NetmikoParsingException
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
RELATIVE_RESOURCE_FOLDER = join(dirname(dirname(relpath(__file__)))... | False | assert | bool_literal | tests/unit/test_utilities.py | test_nokia_context_filter | 546 | null | |
ktbyers/netmiko | from pathlib import Path
import pytest
from unittest.mock import patch, MagicMock
from netmiko.cli_tools import ERROR_PATTERN
from netmiko.cli_tools.helpers import ssh_conn, obtain_devices, update_device_params
BASE_YAML_PATH = Path(__file__).parent / "NETMIKO_YAML"
def mock_connecthandler():
with patch("netmiko... | expected_result | assert | variable | tests/unit/test_clitools_helpers.py | test_update_device_params | 127 | null | |
ktbyers/netmiko | import re
import pytest
from netmiko import file_transfer
def test_verify_space_available_put(scp_fixture):
ssh_conn, scp_transfer = scp_fixture
assert scp_transfer.verify_space_available() is | True | assert | bool_literal | tests/test_netmiko_scp.py | test_verify_space_available_put | 30 | null | |
ktbyers/netmiko | import sys
import pytest
import logging
from netmiko import ConnectHandler, ConnLogOnly, ConnUnify
from netmiko import NetmikoAuthenticationException
from netmiko import NetmikoTimeoutException
from netmiko import ConnectionException
is_linux = sys.platform == "linux" or sys.platform == "linux2"
skip_if_not_linux = py... | 1 | assert | numeric_literal | tests/unit/test_connection.py | test_connlogonly | 49 | null | |
ktbyers/netmiko | from datetime import datetime
def execute_cmd(conn, cmd="show tech-support", read_timeout=None, last_read=2.0):
start_time = datetime.now()
if read_timeout is None:
output = conn.send_command_timing(cmd, last_read=last_read, strip_prompt=False)
else:
output = conn.send_command_timing(
... | 30 | assert | numeric_literal | tests/test_timeout_send_command_timing.py | test_read_traceroute_no_response | 75 | null | |
ktbyers/netmiko | def test_md5_methods(tcl_fixture):
ssh_conn, transfer = tcl_fixture
md5_value = "4313f1adae86a21117441b0a95d482a7"
remote_md5 = transfer.remote_md5()
assert remote_md5 == | md5_value | assert | variable | tests/test_netmiko_tcl.py | test_md5_methods | 38 | null | |
ktbyers/netmiko | from datetime import datetime
def execute_cmd(conn, cmd="show tech-support", read_timeout=None, last_read=2.0):
start_time = datetime.now()
if read_timeout is None:
output = conn.send_command_timing(cmd, last_read=last_read, strip_prompt=False)
else:
output = conn.send_command_timing(
... | 5 | assert | numeric_literal | tests/test_timeout_send_command_timing.py | test_read_traceroute | 105 | null | |
ktbyers/netmiko | from os import path
from datetime import datetime
import pytest
from netmiko import ConnectHandler
from netmiko import NetmikoTimeoutException
from test_utils import parse_yaml
PWD = path.dirname(path.realpath(__file__))
DEVICE_DICT = parse_yaml(PWD + "/etc/test_devices_exc.yml")
def test_valid_conn():
"""Verify ... | "cisco3#" | assert | string_literal | tests/test_netmiko_exceptions.py | test_valid_conn | 17 | null | |
ktbyers/netmiko | import sys
import pytest
import logging
from netmiko import ConnectHandler, ConnLogOnly, ConnUnify
from netmiko import NetmikoAuthenticationException
from netmiko import NetmikoTimeoutException
from netmiko import ConnectionException
is_linux = sys.platform == "linux" or sys.platform == "linux2"
skip_if_not_linux = py... | caplog.text | assert | complex_expr | tests/unit/test_connection.py | test_connlogonly | 48 | null | |
ktbyers/netmiko | import pytest
import time
from os.path import dirname, join
from threading import Lock
import paramiko
from netmiko import NetmikoTimeoutException, log, ConnectHandler
from netmiko.base_connection import BaseConnection
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
def test_sanitize_nothing():
"""Keep... | output | assert | variable | tests/unit/test_base_connection.py | test_sanitize_nothing | 208 | null | |
ktbyers/netmiko | from datetime import datetime
import pytest
import time
import re
from netmiko import ReadTimeout
CLEANUP = True
def my_cleanup(conn, sleep=180):
try:
# Must be long enough for "show tech-support" to finish
time.sleep(sleep)
conn.disconnect()
except Exception:
# If it fails, ju... | allowed_percentage | assert | variable | tests/test_timeout_send_command.py | test_read_timeout | 85 | null | |
ktbyers/netmiko | import pytest
import time
from datetime import datetime
from netmiko import ConnectHandler
def test_disconnect(net_connect, commands, expected_responses):
"""Terminate the SSH session."""
start_time = datetime.now()
net_connect.disconnect()
end_time = datetime.now()
time_delta = end_time - start_ti... | 8 | assert | numeric_literal | tests/test_netmiko_show.py | test_disconnect | 393 | null | |
ktbyers/netmiko | from os import path
from datetime import datetime
import pytest
from netmiko import ConnectHandler
from netmiko import NetmikoTimeoutException
from test_utils import parse_yaml
PWD = path.dirname(path.realpath(__file__))
DEVICE_DICT = parse_yaml(PWD + "/etc/test_devices_exc.yml")
def test_conn_timeout():
device =... | 5.1 | assert | numeric_literal | tests/test_netmiko_exceptions.py | test_conn_timeout | 37 | null | |
ktbyers/netmiko | import os
import sys
from os.path import dirname, join, relpath
import pytest
from netmiko import utilities
from textfsm import clitable
from netmiko.exceptions import NetmikoParsingException
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
RELATIVE_RESOURCE_FOLDER = join(dirname(dirname(relpath(__file__)))... | expected | assert | variable | tests/unit/test_utilities.py | test_load_yaml_file | 117 | null | |
ktbyers/netmiko | import time
import re
import random
import string
import pytest
def gen_random(N=6):
return "".join(
[
random.choice(
string.ascii_lowercase + string.ascii_uppercase + string.digits
)
for x in range(N)
]
)
def retrieve_commands(commands):
... | response_comment | assert | variable | tests/test_netmiko_commit.py | test_commit_label_comment | 368 | null | |
ktbyers/netmiko | from datetime import datetime
import pytest
import time
import re
from netmiko import ReadTimeout
def execute_cmd(conn, pattern, read_timeout, cmd="show tech-support\n", max_loops=None):
conn.write_channel("show tech-support\n")
return conn.read_until_pattern(
pattern=pattern, read_timeout=read_timeout... | 10 | assert | numeric_literal | tests/test_timeout_read_until_pattern.py | test_read_longrunning_cmd | 60 | null | |
ktbyers/netmiko | from os import path
from datetime import datetime
import pytest
from netmiko import ConnectHandler
from netmiko import NetmikoTimeoutException
from test_utils import parse_yaml
PWD = path.dirname(path.realpath(__file__))
DEVICE_DICT = parse_yaml(PWD + "/etc/test_devices_exc.yml")
def test_conn_timeout():
device =... | 5.0 | assert | numeric_literal | tests/test_netmiko_exceptions.py | test_conn_timeout | 36 | null | |
ktbyers/netmiko | import re
import pytest
from netmiko import ConfigInvalidException
from netmiko import ReadTimeout
def test_exit_config_mode(net_connect, commands, expected_responses):
"""Test exit config mode."""
if net_connect._config_mode:
net_connect.exit_config_mode()
assert net_connect.check_config_mode... | False | assert | bool_literal | tests/test_netmiko_config.py | test_exit_config_mode | 50 | null | |
ktbyers/netmiko | import pytest
import os
from netmiko.encryption_handling import encrypt_value, decrypt_value, ENCRYPTION_PREFIX
from netmiko.encryption_handling import get_encryption_key
@pytest.mark.parametrize("encryption_type", ["fernet", "aes128"])
def test_encrypt_decrypt(encryption_type):
original_value = "my_string"
... | original_value | assert | variable | tests/unit/test_encryption_hanlding.py | test_encrypt_decrypt | 42 | null | |
ktbyers/netmiko | import pytest
import time
from os.path import dirname, join
from threading import Lock
import paramiko
from netmiko import NetmikoTimeoutException, log, ConnectHandler
from netmiko.base_connection import BaseConnection
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
def lock_unlock_timeout(timeout=0):
... | "\n" | assert | string_literal | tests/unit/test_base_connection.py | test_strip_ansi_codes | 482 | null | |
ktbyers/netmiko | import pytest
from netmiko.utilities import select_cmd_verify
def bogus_func(obj, *args, **kwargs):
"""Function that just returns the arguments modified by the decorator."""
return (obj, args, kwargs)
def test_send_command_global_cmd_verify(
net_connect_cmd_verify, commands, expected_responses
):
"""
... | show_ip_alt | assert | variable | tests/test_netmiko_cmd_verify.py | test_send_command_global_cmd_verify | 55 | null | |
ktbyers/netmiko | from datetime import datetime
import pytest
import time
import re
from netmiko import ReadTimeout
CLEANUP = True
def my_cleanup(conn, sleep=180):
try:
# Must be long enough for "show tech-support" to finish
time.sleep(sleep)
conn.disconnect()
except Exception:
# If it fails, ju... | 10 | assert | numeric_literal | tests/test_timeout_send_command.py | test_read_longrunning_cmd | 60 | null | |
ktbyers/netmiko | from datetime import datetime
def execute_cmd(conn, cmd="show tech-support", read_timeout=None, last_read=2.0):
start_time = datetime.now()
cmd = cmd.strip()
conn.write_channel(cmd + "\n")
if read_timeout is None:
output = conn.read_channel_timing(last_read=last_read)
else:
output =... | 30 | assert | numeric_literal | tests/test_timeout_read_timing.py | test_read_traceroute_no_response | 92 | null | |
ktbyers/netmiko | import time
import hashlib
import io
import logging
from netmiko import ConnectHandler
from netmiko.session_log import SessionLog
def add_test_name_to_file_name(initial_fname, test_name):
dir_name, f_name = initial_fname.split("/")
new_file_name = f"{dir_name}/{test_name}-{f_name}"
return new_file_name
de... | 2 | assert | numeric_literal | tests/test_netmiko_session_log.py | test_session_log_no_log_cfg | 318 | null | |
ktbyers/netmiko | import time
import re
import random
import string
import pytest
def gen_random(N=6):
return "".join(
[
random.choice(
string.ascii_lowercase + string.ascii_uppercase + string.digits
)
for x in range(N)
]
)
def retrieve_commands(commands):
... | False | assert | bool_literal | tests/test_netmiko_commit.py | test_exit_config_mode | 410 | null | |
ktbyers/netmiko | import pytest
import json
from pathlib import Path
import netmiko.cli_tools.outputters as outputters
def read_file(filename):
file_path = Path(__file__).parent / filename
return file_path.read_text()
def read_json_file(filename):
return json.loads(read_file(filename))
def sample_results():
return {
... | captured.out | assert | complex_expr | tests/unit/test_clitools_outputters.py | test_output_raw | 34 | null | |
ktbyers/netmiko | import pytest
import os
from netmiko.encryption_handling import encrypt_value, decrypt_value, ENCRYPTION_PREFIX
from netmiko.encryption_handling import get_encryption_key
def test_get_encryption_key_missing():
# Ensure the environment variable is not set
if "NETMIKO_TOOLS_KEY" in os.environ:
del os.env... | str(excinfo.value) | assert | func_call | tests/unit/test_encryption_hanlding.py | test_get_encryption_key_missing | 68 | null | |
ktbyers/netmiko | import pytest
import time
from os.path import dirname, join
from threading import Lock
import paramiko
from netmiko import NetmikoTimeoutException, log, ConnectHandler
from netmiko.base_connection import BaseConnection
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
def lock_unlock_timeout(timeout=0):
... | set() | assert | func_call | tests/unit/test_base_connection.py | test_disable_sha2_fix | 554 | null | |
ktbyers/netmiko | import pytest
import time
from os.path import dirname, join
from threading import Lock
import paramiko
from netmiko import NetmikoTimeoutException, log, ConnectHandler
from netmiko.base_connection import BaseConnection
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
def lock_unlock_timeout(timeout=0):
... | "" | assert | string_literal | tests/unit/test_base_connection.py | test_strip_ansi_codes | 478 | null | |
ktbyers/netmiko | import os
import sys
from os.path import dirname, join, relpath
import pytest
from netmiko import utilities
from textfsm import clitable
from netmiko.exceptions import NetmikoParsingException
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
RELATIVE_RESOURCE_FOLDER = join(dirname(dirname(relpath(__file__)))... | b"test" | assert | string_literal | tests/unit/test_utilities.py | test_string_to_bytes | 234 | null | |
ktbyers/netmiko | import re
import pytest
from netmiko import ConfigInvalidException
from netmiko import ReadTimeout
def test_config_mode(net_connect, commands, expected_responses):
"""
Test enter config mode
"""
# Behavior for devices with no config mode is to return null string
config_mode_command = commands.get("... | True | assert | bool_literal | tests/test_netmiko_config.py | test_config_mode | 39 | null | |
ktbyers/netmiko | from pathlib import Path
import pytest
from unittest.mock import patch, MagicMock
from netmiko.cli_tools import ERROR_PATTERN
from netmiko.cli_tools.helpers import ssh_conn, obtain_devices, update_device_params
BASE_YAML_PATH = Path(__file__).parent / "NETMIKO_YAML"
def mock_connecthandler():
with patch("netmiko... | (device_name, ERROR_PATTERN) | assert | collection | tests/unit/test_clitools_helpers.py | test_ssh_conn_failure | 45 | null | |
ktbyers/netmiko | import re
import pytest
from network_utilities import generate_ios_acl
from network_utilities import generate_cisco_nxos_acl # noqa
from network_utilities import generate_cisco_asa_acl # noqa
from network_utilities import generate_cisco_xr_acl # noqa
from network_utilities import generate_arista_eos_acl # noqa
from... | len(cfg_lines) | assert | func_call | tests/test_netmiko_config_acl.py | test_large_acl | 69 | null | |
ktbyers/netmiko | import pytest
from netmiko.utilities import select_cmd_verify
def bogus_func(obj, *args, **kwargs):
"""Function that just returns the arguments modified by the decorator."""
return (obj, args, kwargs)
def test_cmd_verify_decorator(net_connect_cmd_verify):
obj = net_connect_cmd_verify
# Global False sh... | None | assert | none_literal | tests/test_netmiko_cmd_verify.py | test_cmd_verify_decorator | 30 | null | |
ktbyers/netmiko | import pytest
import os
from netmiko.encryption_handling import encrypt_value, decrypt_value, ENCRYPTION_PREFIX
from netmiko.encryption_handling import get_encryption_key
def test_get_encryption_key_success(set_encryption_key):
# Use fixture to mock setting the environment variable
key = "a_test_key"
set_... | key.encode() | assert | func_call | tests/unit/test_encryption_hanlding.py | test_get_encryption_key_success | 55 | null | |
ktbyers/netmiko | import pytest
import time
from os.path import dirname, join
from threading import Lock
import paramiko
from netmiko import NetmikoTimeoutException, log, ConnectHandler
from netmiko.base_connection import BaseConnection
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
def test_strip_no_prompt():
"""Strip... | string | assert | variable | tests/unit/test_base_connection.py | test_strip_no_prompt | 279 | null | |
ktbyers/netmiko | def test_ssh_connect(ssh_autodetect):
"""Verify the connection was established successfully."""
net_conn, real_device_type = ssh_autodetect
device_type = net_conn.autodetect()
print(device_type)
assert device_type == | real_device_type | assert | variable | tests/test_netmiko_autodetect.py | test_ssh_connect | 7 | null | |
ktbyers/netmiko | import os
import sys
from os.path import dirname, join, relpath
import pytest
from netmiko import utilities
from textfsm import clitable
from netmiko.exceptions import NetmikoParsingException
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
RELATIVE_RESOURCE_FOLDER = join(dirname(dirname(relpath(__file__)))... | "172.16.0.1" | assert | string_literal | tests/unit/test_utilities.py | test_get_structured_data_genie | 480 | null | |
ktbyers/netmiko | from datetime import datetime
def execute_cmd(conn, cmd="show tech-support", read_timeout=None, last_read=2.0):
start_time = datetime.now()
cmd = cmd.strip()
conn.write_channel(cmd + "\n")
if read_timeout is None:
output = conn.read_channel_timing(last_read=last_read)
else:
output =... | 5 | assert | numeric_literal | tests/test_timeout_read_timing.py | test_read_traceroute | 122 | null | |
ktbyers/netmiko | import os
import sys
from os.path import dirname, join, relpath
import pytest
from netmiko import utilities
from textfsm import clitable
from netmiko.exceptions import NetmikoParsingException
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
RELATIVE_RESOURCE_FOLDER = join(dirname(dirname(relpath(__file__)))... | CONFIG_FILENAME | assert | variable | tests/unit/test_utilities.py | test_find_cfg_file | 143 | null | |
ktbyers/netmiko | from os import path
from datetime import datetime
import pytest
from netmiko import ConnectHandler
from netmiko import NetmikoTimeoutException
from test_utils import parse_yaml
PWD = path.dirname(path.realpath(__file__))
DEVICE_DICT = parse_yaml(PWD + "/etc/test_devices_exc.yml")
def test_conn_timeout():
device =... | NetmikoTimeoutException) | pytest.raises | variable | tests/test_netmiko_exceptions.py | test_conn_timeout | 32 | null | |
ktbyers/netmiko | import subprocess
def test_entry_points():
cmds = [
"netmiko-grep",
"netmiko-cfg",
"netmiko-show",
]
for cmd in cmds:
r = subprocess.run(["poetry", "run", cmd, "--help"], capture_output=True)
assert r.returncode == | 0 | assert | numeric_literal | tests/unit/test_entry_points.py | test_entry_points | 13 | null | |
ktbyers/netmiko | import time
import re
import random
import string
import pytest
def gen_random(N=6):
return "".join(
[
random.choice(
string.ascii_lowercase + string.ascii_uppercase + string.digits
)
for x in range(N)
]
)
def retrieve_commands(commands):
... | commit_comment.strip() | assert | func_call | tests/test_netmiko_commit.py | test_commit_comment | 284 | null | |
ktbyers/netmiko | import pytest
import time
from datetime import datetime
from netmiko import ConnectHandler
def test_send_multiline_timing(net_connect):
debug = False
if (
"cisco_ios" not in net_connect.device_type
and "cisco_xe" not in net_connect.device_type
):
assert pytest.skip()
count = 1... | 95 | assert | numeric_literal | tests/test_netmiko_show.py | test_send_multiline_timing | 236 | null | |
ktbyers/netmiko | import re
import pytest
from netmiko import file_transfer
def test_file_transfer(scp_file_transfer):
"""Test Netmiko file_transfer function."""
ssh_conn, file_system = scp_file_transfer
platform = ssh_conn.device_type
source_file = f"test_{platform}/test9.txt"
dest_file = "test9.txt"
direction ... | Exception) | pytest.raises | variable | tests/test_netmiko_scp.py | test_file_transfer | 144 | null | |
ktbyers/netmiko | from netmiko.ssh_autodetect import SSH_MAPPER_BASE
def test_ssh_base_mapper_order():
"SSH_MAPPER_BASE should be sorted based on the most common command used." ""
assert SSH_MAPPER_BASE[0][1]["cmd"] == | "show version" | assert | string_literal | tests/unit/test_ssh_autodetect.py | test_ssh_base_mapper_order | 7 | null | |
ktbyers/netmiko | import pytest
import time
from datetime import datetime
from netmiko import ConnectHandler
def test_send_command(net_connect, commands, expected_responses):
"""Verify a command can be sent down the channel successfully using send_command method."""
net_connect.clear_buffer()
show_ip_alt = net_connect.send_... | show_ip_alt | assert | variable | tests/test_netmiko_show.py | test_send_command | 99 | null | |
ktbyers/netmiko | import pytest
from netmiko.utilities import select_cmd_verify
def bogus_func(obj, *args, **kwargs):
"""Function that just returns the arguments modified by the decorator."""
return (obj, args, kwargs)
def test_cmd_verify_decorator(net_connect_cmd_verify):
obj = net_connect_cmd_verify
# Global False sh... | True | assert | bool_literal | tests/test_netmiko_cmd_verify.py | test_cmd_verify_decorator | 22 | null | |
ktbyers/netmiko | from datetime import datetime
def execute_cmd(conn, cmd="show tech-support", read_timeout=None, last_read=2.0):
start_time = datetime.now()
cmd = cmd.strip()
conn.write_channel(cmd + "\n")
if read_timeout is None:
output = conn.read_channel_timing(last_read=last_read)
else:
output =... | 100 | assert | numeric_literal | tests/test_timeout_read_timing.py | test_read_traceroute_no_response_full | 109 | null | |
ktbyers/netmiko | from datetime import datetime
import pytest
import time
import re
from netmiko import ReadTimeout
def execute_cmd(conn, pattern, read_timeout, cmd="show tech-support\n", max_loops=None):
conn.write_channel("show tech-support\n")
return conn.read_until_pattern(
pattern=pattern, read_timeout=read_timeout... | allowed_percentage | assert | variable | tests/test_timeout_read_until_pattern.py | test_read_timeout | 85 | null | |
ktbyers/netmiko | import os
import sys
from os.path import dirname, join, relpath
import pytest
from netmiko import utilities
from textfsm import clitable
from netmiko.exceptions import NetmikoParsingException
RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
RELATIVE_RESOURCE_FOLDER = join(dirname(dirname(relpath(__file__)))... | raw_output | assert | variable | tests/unit/test_utilities.py | test_textfsm_failed_parsing | 377 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.