From ca5601eb1eea581324fb3ad35fac1de663911f20 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 6 Apr 2022 13:02:22 -0400 Subject: Add: unit test for python3-natsort library Add: python3-natsort to requirements/deb-base.txt --- requirements/deb-base.txt | 1 + tests/test_natsort.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/test_natsort.py diff --git a/requirements/deb-base.txt b/requirements/deb-base.txt index 895f3a2..48b8b1e 100644 --- a/requirements/deb-base.txt +++ b/requirements/deb-base.txt @@ -1,4 +1,5 @@ python3-jinja2 +python3-natsort python3-padme python3-urwid python3-xlsxwriter diff --git a/tests/test_natsort.py b/tests/test_natsort.py new file mode 100644 index 0000000..15418b8 --- /dev/null +++ b/tests/test_natsort.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# encoding: utf-8 +# Copyright 2022 Canonical Ltd. +# Written by: +# Rod Smith +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from natsort import natsorted +import unittest + + +class TestSortingOfNetworkSpeeds(unittest.TestCase): + + def test_sortspeeds(self): + # Input taken from cloaker's ens1f0, a Mellanox ConnectX-5 Ex + input = ['1000baseKX/Full', '10000baseKR/Full', '40000baseKR4/Full', + '40000baseCR4/Full', '40000baseSR4/Full', + '40000baseLR4/Full', '25000baseCR/Full', '25000baseKR/Full', + '25000baseSR/Full', '50000baseCR2/Full', '50000baseKR2/Full', + '100000baseKR4/Full', '100000baseSR4/Full', + '100000baseCR4/Full', '100000baseLR4_ER4/Full'] + expected_output = ['1000baseKX/Full', '10000baseKR/Full', + '25000baseCR/Full', '25000baseKR/Full', + '25000baseSR/Full', '40000baseCR4/Full', + '40000baseKR4/Full', '40000baseLR4/Full', + '40000baseSR4/Full', '50000baseCR2/Full', + '50000baseKR2/Full', '100000baseCR4/Full', + '100000baseKR4/Full', '100000baseLR4_ER4/Full', + '100000baseSR4/Full'] + output = natsorted(input) + self.assertEqual(expected_output, output) -- cgit v1.2.3