diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 6028ca60..55f4505c 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: [3.7.12, 3.8.12, 3.9.12] + python-version: [3.8.12, 3.9.12, 3.10.12, 3.11.9] steps: - uses: actions/checkout@v2 @@ -34,22 +34,34 @@ jobs: - name: Install dependencies run: | - sudo python -m pip install --upgrade pip - sudo python -m pip install pylint - sudo python -m pip install -r requirements.txt - sudo python -m pip install -r development.txt - sudo python setup.py install + python -m venv venv + source venv/bin/activate + pip install --upgrade pip + pip install pylint + pip install -r requirements.txt + pip install -r development.txt + python setup.py sdist + ls dist/ + cp dist/jsnapy-*.dev0.tar.gz ../ + cd ../ + tar -xzvf jsnapy-*.dev0.tar.gz + cd jsnapy-*.dev0 + python setup.py install + - name: Analysing the code with pylint run: | - sudo find . -type f -name "*.py" | xargs pylint | grep . + pip install pylint + sudo find ./lib/jnpr/jsnapy -type f -name "*.py" | xargs pylint | grep . - name: Run black tool run: | - sudo python -m pip install -U black; - sudo black --check --exclude="docs|build|tests|samples|venv" . + pip install -U black; + black --check --diff --exclude="docs|build|tests|samples|venv" . - name: Run unit test run: | + source venv/bin/activate + pip install -r development.txt cd tests/unit - sudo nosetests -v --with-coverage --cover-package=jnpr.jsnapy --cover-inclusive -a unit + nose2 --with-coverage -vvvv diff --git a/development.txt b/development.txt index 5982e6e1..479f8b1d 100644 --- a/development.txt +++ b/development.txt @@ -8,3 +8,7 @@ pyflakes # https://launchpad.net/pyflakes coveralls # https://coveralls.io/ unittest2>=0.5.1 # https://pypi.python.org/pypi/unittest2 pytest +pyyaml +ntc_templates==1.4.1 +textfsm==0.4.1 +nose2 diff --git a/lib/jnpr/jsnapy/__init__.py b/lib/jnpr/jsnapy/__init__.py index 7d67505a..52b4f608 100755 --- a/lib/jnpr/jsnapy/__init__.py +++ b/lib/jnpr/jsnapy/__init__.py @@ -24,7 +24,6 @@ class DirStore: # Function added by @gcasella # To check if the user is currently running the installation inside of a virtual environment that was installed using the `python3 -m venv venv` command. def venv_check(): - if hasattr(sys, "real_prefix") or ( hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix ): diff --git a/lib/jnpr/jsnapy/check.py b/lib/jnpr/jsnapy/check.py index 2d632580..80918b0d 100755 --- a/lib/jnpr/jsnapy/check.py +++ b/lib/jnpr/jsnapy/check.py @@ -77,10 +77,8 @@ def generate_snap_file(self, device, prefix, name, reply_format): return snapfile def splitter(self, value): - f = ( - lambda x: x.split("]")[1].count(",") - if "[" in x and "]" in x - else x.count(",") + f = lambda x: ( + x.split("]")[1].count(",") if "[" in x and "]" in x else x.count(",") ) value_list = [x[::-1].strip() for x in value[::-1].split(",", f(value))][::-1] return value_list diff --git a/lib/jnpr/jsnapy/jsnapy.py b/lib/jnpr/jsnapy/jsnapy.py index 0197761b..75ee4886 100755 --- a/lib/jnpr/jsnapy/jsnapy.py +++ b/lib/jnpr/jsnapy/jsnapy.py @@ -731,7 +731,7 @@ def connect_multiple_device( if config_data is not None: self.test_cases = self.extract_test_cases(config_data) # extract test cases - for (iter, key_value) in iteritems(host_dict): + for iter, key_value in iteritems(host_dict): hostname = key_value.get("device") username = self.args.login or key_value.get("username") password = self.args.passwd or key_value.get("passwd") @@ -961,6 +961,10 @@ def action_api_based( res = self.api_based_handling_with_dev( dev, config_data, pre_name, action, post_snap, local=local ) + elif dev is not None: # To handle mode = telnet + res = self.api_based_handling_with_dev( + dev, config_data, pre_name, action, post_snap, local=local + ) else: res = self.api_based_handling( config_data, pre_name, action, post_snap, local=local diff --git a/lib/jnpr/jsnapy/operator.py b/lib/jnpr/jsnapy/operator.py index 68fdf41a..9427ba74 100755 --- a/lib/jnpr/jsnapy/operator.py +++ b/lib/jnpr/jsnapy/operator.py @@ -302,9 +302,9 @@ def exists( "testoperation": "exists", "passed": [], "failed": [], - "test_name": test_name - # 'pre_xml': xml1, - # 'post_xml': xml2 + "test_name": test_name, + # 'pre_xml': xml1, + # 'post_xml': xml2 } count_pass = 0 count_fail = 0 @@ -326,7 +326,6 @@ def exists( # this function will find set of pre and post nodes for given Xpath pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -375,7 +374,6 @@ def exists( ) #### check only in postnode #### if postnode: - for k in range(len(postnode)): # if length of pre node is less than post node, # assign sample node @@ -460,7 +458,7 @@ def not_exists( "testoperation": "not-exists", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -483,7 +481,6 @@ def not_exists( tresult["node_name"] = element pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -612,7 +609,7 @@ def all_same( "testoperation": "all-same", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -631,7 +628,6 @@ def all_same( tresult["node_name"] = element pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -676,7 +672,6 @@ def all_same( tresult["failed"].append(deepcopy(node_value_failed)) else: - tresult["expected_node_value"] = value for i in range(len(post_nodes)): # if length of pre node is less than post node, assign @@ -831,7 +826,7 @@ def is_equal( "testoperation": "is-equal", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -854,7 +849,6 @@ def is_equal( tresult["expected_node_value"] = value pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -1022,7 +1016,7 @@ def not_equal( "testoperation": "not-equal", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -1047,7 +1041,6 @@ def not_equal( tresult["expected_node_value"] = value pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -1214,7 +1207,7 @@ def in_range( "testoperation": "in-range", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -1421,7 +1414,7 @@ def not_range( "testoperation": "not-range", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -1454,7 +1447,6 @@ def not_range( tresult["expected_node_value"] = [range1, range2] pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -1627,7 +1619,7 @@ def is_gt( "testoperation": "is-gt", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -1814,7 +1806,7 @@ def is_lt( "testoperation": "is-lt", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -1839,7 +1831,6 @@ def is_lt( tresult["expected_node_value"] = val1 pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -2001,7 +1992,7 @@ def contains( "testoperation": "contains", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -2026,7 +2017,6 @@ def contains( tresult["expected_node_value"] = value pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -2108,7 +2098,6 @@ def contains( } tresult["passed"].append(deepcopy(node_value_passed)) else: - ## if self._is_ignore_null(ignore_null): self.logger_testop.debug( @@ -2184,7 +2173,7 @@ def not_contains( "testoperation": "not_contains", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -2209,7 +2198,6 @@ def not_contains( tresult["expected_node_value"] = value pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -2291,7 +2279,6 @@ def not_contains( } tresult["failed"].append(deepcopy(node_value_failed)) else: - ## if self._is_ignore_null(ignore_null): self.logger_testop.debug( @@ -2367,7 +2354,7 @@ def is_in( "testoperation": "is-in", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -2392,7 +2379,6 @@ def is_in( tresult["expected_node_value"] = value_list pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -2481,7 +2467,6 @@ def is_in( } tresult["failed"].append(deepcopy(node_value_failed)) else: - ## if self._is_ignore_null(ignore_null): self.logger_testop.debug( @@ -2554,7 +2539,7 @@ def not_in( "testoperation": "not-in", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -2579,7 +2564,6 @@ def not_in( tresult["expected_node_value"] = value_list pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -2668,7 +2652,6 @@ def not_in( } tresult["failed"].append(deepcopy(node_value_failed)) else: - ## if self._is_ignore_null(ignore_null): self.logger_testop.debug( @@ -2741,7 +2724,7 @@ def no_diff( "node_name": ele_list[0], "failed": [], "passed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -2979,7 +2962,7 @@ def list_not_less( "node_name": ele_list[0], "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -3207,7 +3190,6 @@ def list_not_more( pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -3735,7 +3717,7 @@ def regex( "testoperation": "regex", "passed": [], "failed": [], - "test_name": test_name + "test_name": test_name, # 'pre_xml': xml1, # 'post_xml': xml2 } @@ -3760,7 +3742,6 @@ def regex( tresult["expected_node_value"] = value pre_nodes, post_nodes = self._find_xpath(iter, x_path, xml1, xml2) if not post_nodes: - if self._is_ignore_null(ignore_null): self._debug_nodes_logger("Xpath", x_path) res = None @@ -3855,7 +3836,6 @@ def regex( } tresult["failed"].append(deepcopy(node_value_failed)) else: - if self._is_ignore_null(ignore_null): self.logger_testop.debug( colorama.Fore.YELLOW diff --git a/setup.cfg b/setup.cfg index b88034e4..08aedd7e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,2 @@ [metadata] -description-file = README.md +description_file = README.md diff --git a/setup.py b/setup.py index 47f21949..465da77e 100755 --- a/setup.py +++ b/setup.py @@ -16,10 +16,10 @@ else: from configparser import ConfigParser + # Function added by @gcasella # To check if the user is currently running the installation inside of a virtual environment that was installed using the `python3 -m venv venv` command. def venv_check(): - if hasattr(sys, "real_prefix") or ( hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix ): @@ -36,7 +36,7 @@ def set_logging_path(path): with open(path, "rt") as f: config = yaml.load(f.read(), Loader=yaml.FullLoader) - for (handler, value) in iteritems(config["handlers"]): + for handler, value in iteritems(config["handlers"]): if handler == "console": pass else: @@ -56,7 +56,6 @@ def set_logging_path(path): class OverrideInstall(install): def run(self): - for arg in sys.argv: if "--install-data" in arg: break