-
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.
Version 0.0.2, added Datapoint class, basic tests
- Loading branch information
Showing
6 changed files
with
153 additions
and
47 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
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 |
---|---|---|
|
@@ -2,10 +2,9 @@ | |
human readable numbers | ||
''' | ||
|
||
name='khnum' | ||
|
||
__author__ = '[email protected]' | ||
__version__ = '0.0.1' | ||
__version__ = '0.0.2' | ||
|
||
|
||
from .khnum import cnum, hnum | ||
from .datapoint import Datapoint as num | ||
from .khnum import cnum, hnum, pretty |
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,36 @@ | ||
''' | ||
Datapoint class | ||
~~~~~~~~~~~~~~~ | ||
''' | ||
|
||
from . import khnum | ||
|
||
|
||
class Datapoint(): | ||
|
||
''' | ||
represents a human readable number | ||
''' | ||
|
||
def __init__(self, num, units='d'): | ||
''' | ||
returns Datapoint instance | ||
''' | ||
self._num = num | ||
self.cnum = khnum.cnum(num) | ||
self.hnum = khnum.hnum(num, units) | ||
self.type = str(type(num)) | ||
self.units = units | ||
|
||
def __str__(self): | ||
return khnum.pretty(dict(self.__dict__)) | ||
|
||
def update(self, num, units='d'): | ||
''' | ||
update datapoint value with number and (optional) khnum units | ||
''' | ||
self.type = str(type(num)) | ||
self._num = num | ||
self.cnum = khnum.cnum(num) | ||
self.hnum = khnum.hnum(num, units) | ||
self.units = units |
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
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,36 @@ | ||
''' | ||
Khnum basic tests | ||
''' | ||
|
||
from khnum import khnum # export PYTHONPATH=.. | ||
|
||
|
||
def test_datapoint(): | ||
num = khnum.num(1234567890) | ||
assert num.cnum == '1,234,567,890' | ||
assert num.hnum == '1.2B' | ||
|
||
def test_datapoint_bytes(): | ||
num = khnum.num(1234567890, 'byte') | ||
assert num.cnum == '1,234,567,890' | ||
assert num.hnum == '1.2GB' | ||
|
||
def test_datapoint_print(): | ||
num = khnum.num(1234567890) | ||
print(num) | ||
|
||
def test_datapoint_si(): | ||
num = khnum.num(1234567890, 'si') | ||
assert num.cnum == '1,234,567,890' | ||
assert num.hnum == '1.1GiB' | ||
|
||
def test_datapoint_update(): | ||
num = khnum.num(1234567890) | ||
|
||
assert num.cnum == '1,234,567,890' | ||
assert num.hnum == '1.2B' | ||
|
||
num.update(987654321, 'b') | ||
|
||
assert num.cnum == '987,654,321' | ||
assert num.hnum == '987.7MB' |