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 Unit tests from nosetests to Pytest and enable test checks #249

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 20 additions & 18 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
name: Run Tests
on: [push]
name: Python Tests
on:
pull_request:
branches:
jobs:
unit-tests:
test:
runs-on: ubuntu-latest
strategy:
matrix:
version: [2.7, 3.5, 3.6, 3.7, 3.8]

python-version: ['3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements_dev.txt
- name: Test with nosetests
run: |
nosetests tests/unit_tests
- name: Check out code
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements_dev.txt
- name: Run tests
run: |
PYTHONPATH=$(pwd) pytest tests/unit_tests
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ lint:
flake8 imcsdk tests

test:
nosetests -w tests
pytest tests/unit_tests

coverage:
coverage run --source imcsdk setup.py test
Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ wheel==0.38.1
nose==1.3.7
mock==2.0.0
flake8
pytest
52 changes: 26 additions & 26 deletions tests/unit_tests/common/test_imccoreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from nose.tools import assert_equal
import unittest

import imcsdk.imccoreutils as cutil


def test_001_get_naming_props():
rn_pattern = "fault-[code]-[name]-[type]-xyz-[state]"
rn_str = "fault-F35275-fault-c2-xyz-on"
np = cutil.get_naming_props(rn_str, rn_pattern)
assert_equal(np['code'], 'F35275')
assert_equal(np['name'], 'fault')
assert_equal(np['type'], 'c2')
assert_equal(np['state'], 'on')


def test_002_get_naming_props():
rn_pattern = "[suport_type][card_param_type]"
rn_str = "11"
np = cutil.get_naming_props(rn_str, rn_pattern)
assert_equal(np['suport_type'], '1')
assert_equal(np['card_param_type'], '1')


def test_003_get_naming_props():
rn_pattern = "[suport_type][card_param_type]"
rn_str = "1122"
np = cutil.get_naming_props(rn_str, rn_pattern)
assert_equal(np['suport_type'], '112')
assert_equal(np['card_param_type'], '2')
class TestImcCoreUtils(unittest.TestCase):
def test_001_get_naming_props(self):
rn_pattern = "fault-[code]-[name]-[type]-xyz-[state]"
rn_str = "fault-F35275-fault-c2-xyz-on"
np = cutil.get_naming_props(rn_str, rn_pattern)
assert np['code'] == 'F35275'
assert np['name'] == 'fault'
assert np['type'] == 'c2'
assert np['state'] == 'on'


def test_002_get_naming_props(self):
rn_pattern = "[suport_type][card_param_type]"
rn_str = "11"
np = cutil.get_naming_props(rn_str, rn_pattern)
assert np['suport_type'] == '1'
assert np['card_param_type'] == '1'


def test_003_get_naming_props(self):
rn_pattern = "[suport_type][card_param_type]"
rn_str = "1122"
np = cutil.get_naming_props(rn_str, rn_pattern)
assert np['suport_type'] == '112'
assert np['card_param_type'] == '2'
48 changes: 24 additions & 24 deletions tests/unit_tests/common/test_imcfromxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from nose.tools import assert_equal
import unittest

class TestImcFromXml(unittest.TestCase):
def test_001_mo_from_xml(self):
import imcsdk.imcxmlcodec as xc

def test_001_mo_from_xml():
import imcsdk.imcxmlcodec as xc
response_str = '''
<configResolveClass cookie="0002618494/31e2450c-0262-1262-8802-0d8fd9f6083c" response="yes" classId="computeRackUnit">
<outConfigs>
<computeRackUnit dn="sys/rack-unit-1" adminPower="policy" availableMemory="131072" model="UCSC-C240-M3L" memorySpeed="1600" name="UCS C240 M3L" numOfAdaptors="1" numOfCores="16" numOfCoresEnabled="16" numOfCpus="2" numOfEthHostIfs="2" numOfFcHostIfs="2" numOfThreads="32" operPower="on" originalUuid="4A42480B-345D-4CD0-8824-A399795E279C" presence="equipped" serverId="1" serial="FCH1752V07Z" totalMemory="131072" usrLbl="hffgfg" uuid="4A42480B-345D-4CD0-8824-A399795E279C" vendor="Cisco Systems Inc" cimcResetReason="watchdog-reset">

response_str = '''
<configResolveClass cookie="0002618494/31e2450c-0262-1262-8802-0d8fd9f6083c" response="yes" classId="computeRackUnit">
<outConfigs>
<computeRackUnit dn="sys/rack-unit-1" adminPower="policy" availableMemory="131072" model="UCSC-C240-M3L" memorySpeed="1600" name="UCS C240 M3L" numOfAdaptors="1" numOfCores="16" numOfCoresEnabled="16" numOfCpus="2" numOfEthHostIfs="2" numOfFcHostIfs="2" numOfThreads="32" operPower="on" originalUuid="4A42480B-345D-4CD0-8824-A399795E279C" presence="equipped" serverId="1" serial="FCH1752V07Z" totalMemory="131072" usrLbl="hffgfg" uuid="4A42480B-345D-4CD0-8824-A399795E279C" vendor="Cisco Systems Inc" cimcResetReason="watchdog-reset">
<networkAdapterUnit slot="L" model="Intel Onboard 1Gbps Ethernet Adapter" numIntf="4" presence="equipped" rn="network-adapter-L" >
<networkAdapterEthIf id="1" mac="3c:08:f6:d9:8f:12" rn="eth-1" ></networkAdapterEthIf>
<networkAdapterEthIf id="2" mac="3c:08:f6:d9:8f:13" rn="eth-2" ></networkAdapterEthIf>
<networkAdapterEthIf id="3" mac="3c:08:f6:d9:8f:14" rn="eth-3" ></networkAdapterEthIf>
</networkAdapterUnit>
</computeRackUnit>
</outConfigs>
</configResolveClass>
'''

<networkAdapterUnit slot="L" model="Intel Onboard 1Gbps Ethernet Adapter" numIntf="4" presence="equipped" rn="network-adapter-L" >
<networkAdapterEthIf id="1" mac="3c:08:f6:d9:8f:12" rn="eth-1" ></networkAdapterEthIf>
<networkAdapterEthIf id="2" mac="3c:08:f6:d9:8f:13" rn="eth-2" ></networkAdapterEthIf>
<networkAdapterEthIf id="3" mac="3c:08:f6:d9:8f:14" rn="eth-3" ></networkAdapterEthIf>
</networkAdapterUnit>
</computeRackUnit>
</outConfigs>
</configResolveClass>
'''

response = xc.from_xml_str(response_str)
assert_equal(response.out_configs.child[0].__class__.__name__,
'ComputeRackUnit')
assert_equal(response.out_configs.child[0].child[0].__class__.__name__,
'NetworkAdapterUnit')
assert_equal(response.out_configs.child[0].child[0].child[0].__class__.__name__,
'NetworkAdapterEthIf')
response = xc.from_xml_str(response_str)
assert (response.out_configs.child[0].__class__.__name__ ==
'ComputeRackUnit')
assert (response.out_configs.child[0].child[0].__class__.__name__ ==
'NetworkAdapterUnit')
assert (response.out_configs.child[0].child[0].child[0].__class__.__name__ ==
'NetworkAdapterEthIf')
12 changes: 6 additions & 6 deletions tests/unit_tests/common/test_imchandle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest

from nose.tools import assert_equal
from imcsdk.imchandle import ImcHandle


def test_001_create_handle():
handle = ImcHandle("192.168.1.1", "admin", "my_extra_secure_password")
assert_equal(handle.username, "admin")
assert_equal(handle.ip, "192.168.1.1")
class TestImcHandle(unittest.TestCase):
def test_001_create_handle(self):
handle = ImcHandle("192.168.1.1", "admin", "my_extra_secure_password")
assert handle.username == "admin"
assert handle.ip == "192.168.1.1"

31 changes: 16 additions & 15 deletions tests/unit_tests/common/test_imcmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from nose.tools import assert_equal, raises
from imcsdk.imcmo import ManagedObject
import unittest

from imcsdk.imcmo import ManagedObject

@raises(Exception)
def test_001_create_mo_directly():
# Create a Managed Object by specifying the classId and parent dn
# this should raise an exception as the associated Meta's will not
# be initialised.
ManagedObject("aaaUser", "sys/user-ext/user-1")
class TestImcMo(unittest.TestCase):
def test_001_create_mo_directly(self):
# Create a Managed Object by specifying the classId and parent dn
# this should raise an exception as the associated Meta's will not
# be initialised.
with self.assertRaises(Exception):
ManagedObject("aaaUser", "sys/user-ext/user-1")


def test_002_create_specific_obj():
# Create an object of type AaaUser with parent dn specified
# check if the object has the right values populated
from imcsdk.mometa.aaa.AaaUser import AaaUser
obj = AaaUser(parent_mo_or_dn="sys/user-ext", id="10")
assert_equal(obj.id, "10")
assert_equal(obj.dn, "sys/user-ext/user-10")
def test_002_create_specific_obj(self):
# Create an object of type AaaUser with parent dn specified
# check if the object has the right values populated
from imcsdk.mometa.aaa.AaaUser import AaaUser
obj = AaaUser(parent_mo_or_dn="sys/user-ext", id="10")
assert obj.id == "10"
assert obj.dn == "sys/user-ext/user-10"
54 changes: 26 additions & 28 deletions tests/unit_tests/common/test_imcpropval.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,46 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest

from nose.tools import *
from imcsdk.mometa.compute.ComputeRackUnit import ComputeRackUnit
from imcsdk.mometa.power.PowerBudget import PowerBudget

obj = None


def setup_func():
global obj
obj = ComputeRackUnit(parent_mo_or_dn="sys", server_id="1")
class TestImcPropVal(unittest.TestCase):
def setUp(self):
global obj
obj = ComputeRackUnit(parent_mo_or_dn="sys", server_id="1")

def teardown_func():
pass
def tearDown(self):
pass


@with_setup(setup_func, teardown_func)
@raises(Exception)
def test_001_set_ro_property():
# This is a read only property
# Should fail with an exception
obj.available_memory = "22334"
def test_001_set_ro_property(self):
# This is a read only property
# Should fail with an exception
with self.assertRaises(Exception):
obj.available_memory = "22334"


@with_setup(setup_func, teardown_func)
def test_002_set_rw_property():
# This is a read write property.
# Should happen without any issues
obj.status = "created"
def test_002_set_rw_property(self):
# This is a read write property.
# Should happen without any issues
obj.status = "created"


@with_setup(setup_func(), teardown_func())
@raises(Exception)
def test_003_set_naming_property():
# This is a naming property. so, it is create only
# Should fail with an exception
obj.server_id = "15"
def test_003_set_naming_property(self):
# This is a naming property. so, it is create only
# Should fail with an exception
with self.assertRaises(Exception):
obj.server_id = "15"


def test_004_set_rw_ro_property():
obj = PowerBudget(parent_mo_or_dn='sys/rack-unit-1')
obj.status = 'modified'
def test_004_set_rw_ro_property(self):
obj = PowerBudget(parent_mo_or_dn='sys/rack-unit-1')
obj.status = 'modified'

obj = PowerBudget(parent_mo_or_dn='sys/chassis-1/server-1')
obj.status = 'modified'
obj = PowerBudget(parent_mo_or_dn='sys/chassis-1/server-1')
obj.status = 'modified'
Loading