Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test): cover registering metrics, utils
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 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,11 @@ | ||
import prometheus_express.metric as pm | ||
import prometheus_express.registry as pr | ||
import unittest | ||
|
||
class RegistryTest(unittest.TestCase): | ||
def test_register(self): | ||
m = pm.Metric('foo', 'foo counts') | ||
r = pr.CollectorRegistry() | ||
r.register(m) | ||
r.register(m) | ||
self.assertEqual(r.metrics, set([m])) |
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,60 @@ | ||
import prometheus_express.utils as pu | ||
import unittest | ||
|
||
class MockI2C(object): | ||
def __init__(self, locked=False, devices=[]): | ||
self.devices = devices | ||
self.locked = locked | ||
|
||
def try_lock(self): | ||
if self.locked: | ||
return False | ||
else: | ||
self.locked = True | ||
return True | ||
|
||
def scan(self): | ||
return self.devices | ||
|
||
def unlock(self): | ||
self.locked = False | ||
|
||
class MockNetwork(object): | ||
def __init__(self, connected=False, ip='0.0.0.0'): | ||
self.connected = connected | ||
self.ip = ip | ||
|
||
def ifconfig(self): | ||
return [self.ip] | ||
|
||
class CheckNetworkTest(unittest.TestCase): | ||
def test_unconnected(self): | ||
self.assertEqual( | ||
pu.check_network(MockNetwork()), | ||
False, | ||
) | ||
|
||
def test_connected_nullip(self): | ||
self.assertEqual( | ||
pu.check_network(MockNetwork(connected=True)), | ||
False, | ||
) | ||
|
||
def test_connected_withip(self): | ||
self.assertEqual( | ||
pu.check_network(MockNetwork(connected=True, ip='1.1.1.1')), | ||
True, | ||
) | ||
|
||
class ScanI2CBusTest(unittest.TestCase): | ||
def test_unlocked(self): | ||
self.assertEqual( | ||
pu.scan_i2c_bus(MockI2C()), | ||
True, | ||
) | ||
|
||
def test_locked(self): | ||
self.assertEqual( | ||
pu.scan_i2c_bus(MockI2C(locked=True)), | ||
False, | ||
) |