From cdbf4cf5ec8e46f4a02b247fbd0f11e6b52b25b2 Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Mon, 20 Feb 2017 16:35:53 -0800 Subject: [PATCH 1/3] Initial pass at tests --- tests/test_modules/eos/test_mathUtils.py | 12 ++++++ tests/test_modules/gui/test_aboutData.py | 8 ++++ tests/test_modules/service/test_attribute.py | 41 ++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 tests/test_modules/eos/test_mathUtils.py create mode 100644 tests/test_modules/gui/test_aboutData.py create mode 100644 tests/test_modules/service/test_attribute.py diff --git a/tests/test_modules/eos/test_mathUtils.py b/tests/test_modules/eos/test_mathUtils.py new file mode 100644 index 000000000..021bff977 --- /dev/null +++ b/tests/test_modules/eos/test_mathUtils.py @@ -0,0 +1,12 @@ +from eos.mathUtils import floorFloat + + +def test_floorFloat(): + assert type(floorFloat(1)) is not float + assert type(floorFloat(1)) is int + assert type(floorFloat(1.1)) is not float + assert type(floorFloat(1.1)) is int + assert floorFloat(1.1) == 1 + assert floorFloat(1.9) == 1 + assert floorFloat(1.5) == 1 + assert floorFloat(-1.5) == -1 diff --git a/tests/test_modules/gui/test_aboutData.py b/tests/test_modules/gui/test_aboutData.py new file mode 100644 index 000000000..f98cf3244 --- /dev/null +++ b/tests/test_modules/gui/test_aboutData.py @@ -0,0 +1,8 @@ +from gui.aboutData import versionString, licenses, developers, credits, description + +def test_aboutData(): + assert versionString.__len__() > 0 + assert licenses.__len__() > 0 + assert developers.__len__() > 0 + assert credits.__len__() > 0 + assert description.__len__() > 0 diff --git a/tests/test_modules/service/test_attribute.py b/tests/test_modules/service/test_attribute.py new file mode 100644 index 000000000..a2215a17b --- /dev/null +++ b/tests/test_modules/service/test_attribute.py @@ -0,0 +1,41 @@ +from service.attribute import Attribute + +def test_attribute(): + """ + We don't really have much to test here, to throw a generic attribute at it and validate we get the expected results + + :return: + """ + sAttr = Attribute.getInstance() + info = sAttr.getAttributeInfo("maxRange") + + assert info.attributeID == 54 + assert type(info.attributeID) is int + assert info.attributeName == 'maxRange' + assert type(info.attributeName) is unicode + assert info.defaultValue == 0.0 + assert type(info.defaultValue) is float + assert info.description == 'Distance below which range does not affect the to-hit equation.' + assert type(info.description) is unicode + assert info.displayName == 'Optimal Range' + assert type(info.displayName) is unicode + assert info.highIsGood == True + assert type(info.highIsGood) is bool + assert info.iconID == 1391 + assert type(info.iconID) is int + assert info.name == 'maxRange' + assert type(info.name) is unicode + assert info.published == True + assert type(info.published) is bool + assert info.unitID == 1 + assert type(info.unitID) is int + assert info.unit.ID == 1 + assert type(info.unit.ID) is int + assert info.unit.displayName == 'm' + assert type(info.unit.displayName) is unicode + assert info.unit.name == 'Length' + assert type(info.unit.name) is unicode + assert info.unit.unitID == 1 + assert type(info.unit.unitID) is int + assert info.unit.unitName == 'Length' + assert type(info.unit.unitName) is unicode From 565a78610e467f50ffd78effc0b4e1a00b9c84ae Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Tue, 21 Feb 2017 07:38:32 -0800 Subject: [PATCH 2/3] Fix floorfloat, and pep8 fixes for tests --- eos/mathUtils.py | 10 ++-------- tests/test_modules/gui/test_aboutData.py | 1 + tests/test_modules/service/test_attribute.py | 5 +++-- tests/test_package.py | 4 ++-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/eos/mathUtils.py b/eos/mathUtils.py index 5de12c60f..845bb4844 100644 --- a/eos/mathUtils.py +++ b/eos/mathUtils.py @@ -17,15 +17,9 @@ # along with eos. If not, see . # =============================================================================== -import decimal +from math import floor def floorFloat(value): - """Round float down to integer""" - # We have to convert float to str to keep compatibility with - # decimal module in python 2.6 - value = str(value) - # Do the conversions for proper rounding down, avoiding float - # representation errors - result = int(decimal.Decimal(value).to_integral_value(rounding=decimal.ROUND_DOWN)) + result = int(floor(value)) return result diff --git a/tests/test_modules/gui/test_aboutData.py b/tests/test_modules/gui/test_aboutData.py index f98cf3244..8e7e862d6 100644 --- a/tests/test_modules/gui/test_aboutData.py +++ b/tests/test_modules/gui/test_aboutData.py @@ -1,5 +1,6 @@ from gui.aboutData import versionString, licenses, developers, credits, description + def test_aboutData(): assert versionString.__len__() > 0 assert licenses.__len__() > 0 diff --git a/tests/test_modules/service/test_attribute.py b/tests/test_modules/service/test_attribute.py index a2215a17b..1ab44f2a8 100644 --- a/tests/test_modules/service/test_attribute.py +++ b/tests/test_modules/service/test_attribute.py @@ -1,5 +1,6 @@ from service.attribute import Attribute + def test_attribute(): """ We don't really have much to test here, to throw a generic attribute at it and validate we get the expected results @@ -19,13 +20,13 @@ def test_attribute(): assert type(info.description) is unicode assert info.displayName == 'Optimal Range' assert type(info.displayName) is unicode - assert info.highIsGood == True + assert info.highIsGood is True assert type(info.highIsGood) is bool assert info.iconID == 1391 assert type(info.iconID) is int assert info.name == 'maxRange' assert type(info.name) is unicode - assert info.published == True + assert info.published is True assert type(info.published) is bool assert info.unitID == 1 assert type(info.unitID) is int diff --git a/tests/test_package.py b/tests/test_package.py index 2788e4509..5f97967d7 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -2,10 +2,10 @@ import os import sys -import importlib +# import importlib # noinspection PyPackageRequirements -import pytest +# import pytest script_dir = os.path.dirname(os.path.abspath(__file__)) From a07e1d8f3a7b1f881f6651d8a5d433ae9e151fb0 Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Tue, 21 Feb 2017 07:43:04 -0800 Subject: [PATCH 3/3] Test actual correct value, not the wrong value that was being generated by old hacky method. --- tests/test_modules/eos/test_mathUtils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_modules/eos/test_mathUtils.py b/tests/test_modules/eos/test_mathUtils.py index 021bff977..c5cf2b0bb 100644 --- a/tests/test_modules/eos/test_mathUtils.py +++ b/tests/test_modules/eos/test_mathUtils.py @@ -9,4 +9,4 @@ def test_floorFloat(): assert floorFloat(1.1) == 1 assert floorFloat(1.9) == 1 assert floorFloat(1.5) == 1 - assert floorFloat(-1.5) == -1 + assert floorFloat(-1.5) == -2