forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[syseepromd] Add unit tests; Refactor to allow for greater unit test …
…coverage (sonic-net#156) - Refactor syseepromd to eliminate infinite loops to allow for increased unit test coverage - Refactor signal handler and ensure daemon always exits with non-zero exit code so that supervisor will restart it - Add unit tests Unit test coverage increases from 0% to 90%
- Loading branch information
Showing
11 changed files
with
418 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
addopts = --cov=scripts --cov-report html --cov-report term --cov-report xml --junitxml=test-results.xml -vv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[aliases] | ||
test=pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
6 changes: 6 additions & 0 deletions
6
sonic-syseepromd/tests/mocked_libs/sonic_platform/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
""" | ||
Mock implementation of sonic_platform package for unit testing | ||
""" | ||
|
||
from . import chassis | ||
from . import platform |
21 changes: 21 additions & 0 deletions
21
sonic-syseepromd/tests/mocked_libs/sonic_platform/chassis.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
Mock implementation of sonic_platform package for unit testing | ||
""" | ||
|
||
# TODO: Clean this up once we no longer need to support Python 2 | ||
import sys | ||
if sys.version_info.major == 3: | ||
from unittest import mock | ||
else: | ||
import mock | ||
|
||
from sonic_platform_base.chassis_base import ChassisBase | ||
|
||
|
||
class Chassis(ChassisBase): | ||
def __init__(self): | ||
ChassisBase.__init__(self) | ||
self.eeprom = mock.MagicMock() | ||
|
||
def get_eeprom(self): | ||
return self.eeprom |
12 changes: 12 additions & 0 deletions
12
sonic-syseepromd/tests/mocked_libs/sonic_platform/platform.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
Mock implementation of sonic_platform package for unit testing | ||
""" | ||
|
||
from sonic_platform_base.platform_base import PlatformBase | ||
from sonic_platform.chassis import Chassis | ||
|
||
|
||
class Platform(PlatformBase): | ||
def __init__(self): | ||
PlatformBase.__init__(self) | ||
self._chassis = Chassis() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
''' | ||
Mock implementation of swsscommon package for unit testing | ||
''' | ||
|
||
from . import swsscommon |
51 changes: 51 additions & 0 deletions
51
sonic-syseepromd/tests/mocked_libs/swsscommon/swsscommon.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
''' | ||
Mock implementation of swsscommon package for unit testing | ||
''' | ||
|
||
STATE_DB = '' | ||
|
||
|
||
class Table: | ||
def __init__(self, db, table_name): | ||
self.table_name = table_name | ||
self.mock_dict = {} | ||
|
||
def _del(self, key): | ||
del self.mock_dict[key] | ||
pass | ||
|
||
def set(self, key, fvs): | ||
self.mock_dict[key] = fvs.fv_dict | ||
pass | ||
|
||
def get(self, key): | ||
if key in self.mock_dict: | ||
return self.mock_dict[key] | ||
return None | ||
|
||
|
||
class FieldValuePairs: | ||
fv_dict = {} | ||
|
||
def __init__(self, tuple_list): | ||
if isinstance(tuple_list, list) and isinstance(tuple_list[0], tuple): | ||
self.fv_dict = dict(tuple_list) | ||
|
||
def __setitem__(self, key, kv_tuple): | ||
self.fv_dict[kv_tuple[0]] = kv_tuple[1] | ||
|
||
def __getitem__(self, key): | ||
return self.fv_dict[key] | ||
|
||
def __eq__(self, other): | ||
if not isinstance(other, FieldValuePairs): | ||
# don't attempt to compare against unrelated types | ||
return NotImplemented | ||
|
||
return self.fv_dict == other.fv_dict | ||
|
||
def __repr__(self): | ||
return repr(self.fv_dict) | ||
|
||
def __str__(self): | ||
return repr(self.fv_dict) |
Oops, something went wrong.