Skip to content

Commit

Permalink
Merge branch 'feature/test-coverage' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
eve-n0rman committed Feb 19, 2021
2 parents 8bc8241 + 0259f71 commit bd1321d
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 21 deletions.
5 changes: 3 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[pytest]
addopts = --doctest-modules --cov-report xml --cov=structurebot
addopts = -x --doctest-modules --cov-report xml --cov=structurebot
doctest_optionflags = ELLIPSIS
testpaths =
tests
structurebot
structurebot
110 changes: 94 additions & 16 deletions structurebot/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,64 @@
from collections import Counter
from methodtools import lru_cache

from config import CONFIG
from util import esi, esi_client, name_to_id, names_to_ids, HTTPError


logger = logging.getLogger(__name__)


def is_system_id(location_id):
if location_id >= 30000000 and location_id <= 32000000:
"""Determines if an ID is in the CCP defined system ID range
https://github.com/esi/eve-glue/blob/master/eve_glue/location_type.py
Args:
location_id (integer): ESI provided ID
Returns:
boolean: is or is not a system id
>>> is_system_id(30000000)
True
>>> is_system_id(60000000)
False
"""
if location_id >= 30000000 and location_id <= 39999999:
return True
else:
return False
return False


def is_station_id(location_id):
"""Determines if an ID is in the CCP defined station ID range
https://github.com/esi/eve-glue/blob/master/eve_glue/location_type.py
Args:
location_id (integer): ESI provided ID
Returns:
boolean: is or is not a station id
>>> is_station_id(60000000)
True
>>> is_station_id(30000000)
False
"""
if location_id >= 60000000 and location_id <= 64000000:
return True
else:
return False
return False


class Category(object):
"""docstring for Category"""
"""EVE SDE item category
https://esi.evetech.net/ui/#/Universe/get_universe_categories_category_id
Args:
category_id (integer): ESI provided category ID
name (string): ESI provided category name
published (boolean): published item
groups (list): ESI provided list of member group IDs
"""
def __init__(self, category_id, name, published, groups):
"""Create new Category"""
super(Category, self).__init__()
self.category_id = category_id
self.name = name
Expand All @@ -35,6 +71,18 @@ def __init__(self, category_id, name, published, groups):
@lru_cache(maxsize=1000)
@classmethod
def from_id(cls, id):
"""Creates a new Category from a ESI provided category ID
Args:
id (integer): ESI provided category ID
Raises:
ValueError: id not an integer
HTTPError: ESI error
Returns:
Category: new category from id
"""
if not isinstance(id, int):
raise ValueError('Type ID must be an integer')
op = 'get_universe_categories_category_id'
Expand All @@ -47,16 +95,33 @@ def from_id(cls, id):

@classmethod
def from_ids(cls, ids):
"""Returns a list of Category's given a list of ESI category IDs
Args:
id (integer): ESI provided category ID
Returns:
list: list of Category's
"""
types = []
for id in ids:
types.append(cls.from_id(id))
return types


class Group(object):
"""docstring for Group"""
"""EVE SDE item group
https://esi.evetech.net/ui/#/Universe/get_universe_groups_group_id
Args:
group_id (integer): ESI provided group ID
name (string): ESI provided group name
published (boolean): published item
category (integer): ESI provided parent category
"""
def __init__(self, group_id, name, published, category_id, types,
category=None):
"""Create new Group"""
super(Group, self).__init__()
self.group_id = group_id
self.name = name
Expand All @@ -68,6 +133,18 @@ def __init__(self, group_id, name, published, category_id, types,
@lru_cache(maxsize=1000)
@classmethod
def from_id(cls, id):
"""Creates a new Group from a ESI provided group ID
Args:
id (integer): ESI provided group ID
Raises:
ValueError: id not an integer
HTTPError: ESI error
Returns:
Group: new Group from id
"""
if not isinstance(id, int):
raise ValueError('Type ID must be an integer')
type_request = esi.op['get_universe_groups_group_id'](group_id=id)
Expand All @@ -79,6 +156,14 @@ def from_id(cls, id):

@classmethod
def from_ids(cls, ids):
"""Returns a list of Group's given a list of ESI group IDs
Args:
id (integer): ESI provided group ID
Returns:
list: list of Group's
"""
types = []
for id in ids:
types.append(cls.from_id(id))
Expand Down Expand Up @@ -287,13 +372,6 @@ def from_entity_name(cls, name):
return cls.from_entity_id(id, id_type)


def is_system_id(location_id):
if location_id >= 30000000 and location_id <= 32000000:
return True
else:
return False


class Fitting(object):
"""docstring for Fitting"""

Expand Down Expand Up @@ -339,7 +417,7 @@ def _name_count(asset):

def __cmp__(self, other):
if not isinstance(other, Fitting):
raise NotImplemented
raise NotImplementedError
equality = 0
for slot in Fitting.slots:
item_counts = {i.type_id: i.quantity-1 for i in getattr(self, slot)}
Expand Down
2 changes: 1 addition & 1 deletion structurebot/citadels.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, structure_id, corporation_id=None, type_id=None, type_name=No
self.corporation_id = corporation_id
self.type_id = type_id
self.type = Type.from_id(type_id)
self.type_name = type_name
self.type_name = type_name or self.type.name
self.system_id = system_id
self.fuel = fuel
self.fuel_expires = getattr(fuel_expires, 'v', None)
Expand Down
40 changes: 39 additions & 1 deletion tests/test_assets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import unittest
import doctest
import pytest
import structurebot.assets
from structurebot.assets import Fitting, Asset, Type
from structurebot.assets import Fitting, Asset, Type, Category, Group, BaseType
from structurebot.config import CONFIG
from structurebot.util import HTTPError


def load_tests(loader, tests, ignore):
Expand All @@ -26,6 +28,33 @@ def setUpClass(cls):
FighterBay=[test_fighter])
cls.fittings.append(fitting)

def test_category(self):
cats = Category.from_ids([1, 2])
for cat in cats:
self.assertIsInstance(cat, Category)
with pytest.raises(ValueError):
Category.from_id('string')
with pytest.raises(HTTPError):
Category.from_id(9999)

def test_group(self):
groups = Group.from_ids([1,2])
for group in groups:
self.assertIsInstance(group, Group)
with pytest.raises(ValueError):
Group.from_id('string')
with pytest.raises(HTTPError):
Group.from_id(9999)

def test_basetype(self):
basetypes = BaseType.from_ids([0,2])
for basetype in basetypes:
self.assertIsInstance(basetype, BaseType)
with pytest.raises(ValueError):
BaseType.from_id('string')
with pytest.raises(HTTPError):
BaseType.from_id(99999)

def test_group_category(self):
control_tower = Type.from_name('Amarr Control Tower')
self.assertEqual(control_tower.group.name, 'Control Tower')
Expand All @@ -34,6 +63,11 @@ def test_group_category(self):
def test_assets(self):
self.assertGreater(len(self.assets), 1)

def test_fitting_str(self):
self.assertEqual(str(self.fittings[-1]),
'FighterBay: Standup Einherji I (2)\n'
'MedSlot: Standup Target Painter I')

def test_fitting_equality(self):
self.assertEquals(self.fittings[0], self.fittings[0])

Expand All @@ -48,3 +82,7 @@ def test_fitting_less_quantity(self):

def test_fitting_greater_quantity(self):
self.assertGreater(self.fittings[3], self.fittings[2])

def test_fitting_bad_compare(self):
with pytest.raises(NotImplementedError):
self.fittings[0] == 'not a fitting'
43 changes: 42 additions & 1 deletion tests/test_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class TestStructureDogma(unittest.TestCase):
def setUpClass(cls):
raitaru_type = assets.Type.from_name('Raitaru')
ansiblex_type = assets.Type.from_name('Ansiblex Jump Gate')
athanor_type = assets.Type.from_name('Athanor')
manufacturing_type = assets.Type.from_name('Standup Manufacturing Plant I')
drill_type = assets.Type.from_name('Standup Moon Drill I')
research_type = assets.Type.from_name('Standup Research Lab I')
quantum_core = assets.Type.from_name('Raitaru Upwell Quantum Core')
fuel_expires = Datetime()
Expand All @@ -46,7 +48,7 @@ def setUpClass(cls):
type_name=raitaru_type.name)
unanchors_at = Datetime()
unanchors_at.apply_with(None, now + dt.timedelta(days=2), None)
cls.unanchoring_raitaru = citadels.Structure(1, type_id=raitaru_type.type_id,
cls.unanchoring_raitaru = citadels.Structure(2, type_id=raitaru_type.type_id,
type_name=raitaru_type.name,
fitting=uncored_fitting,
fuel_expires=fuel_expires,
Expand All @@ -58,6 +60,27 @@ def setUpClass(cls):
fitting=raitaru_no_core_fitting)
cls.ansiblex = citadels.Structure(3, type_id=ansiblex_type.type_id,
type_name=ansiblex_type.name)
detonates_at = Datetime()
detonates_at.apply_with(None, now + dt.timedelta(hours=12), None)
long_detonates_at = Datetime()
long_detonates_at.apply_with(None, now + dt.timedelta(days=21), None)
athanor_fitting = assets.Fitting(ServiceSlot=[drill_type])
drill_service = {'name': 'Moon Drilling', 'state': 'online'}
cls.detonating_athanor = citadels.Structure(3, type_id=athanor_type.type_id,
type_name=athanor_type.name,
fitting=athanor_fitting,
services=[drill_service],
detonation=detonates_at)
cls.long_detonating_athanor = citadels.Structure(4, type_id=athanor_type.type_id,
type_name=athanor_type.name,
fitting=athanor_fitting,
services=[drill_service],
detonation=long_detonates_at)
cls.unscheduled_athanor = citadels.Structure(5, type_id=athanor_type.type_id,
type_name=athanor_type.name,
fitting=athanor_fitting,
services=[drill_service])


def test_fitting(self):
self.assertTrue(self.raitaru.fitting)
Expand All @@ -82,3 +105,21 @@ def test_core(self):
self.assertFalse(self.raitaru.needs_core)
self.assertTrue(self.no_core_raitaru.needs_core)
self.assertFalse(self.ansiblex.needs_core)

def test_detonations(self):
self.assertFalse(self.detonating_athanor.needs_detonation)
self.assertTrue(self.unscheduled_athanor.needs_detonation)
self.assertTrue(self.detonating_athanor.detonates_soon)
self.assertFalse(self.unscheduled_athanor.detonates_soon)
self.assertFalse(self.raitaru.detonates_soon)
self.assertFalse(self.long_detonating_athanor.detonates_soon)

def test_inaccessible(self):
goonstar = citadels.Structure(1022734985679, type_id=35834)
self.assertEqual(goonstar.name, 'Inaccessible Structure')
self.assertFalse(goonstar.accessible)

def test_accessible(self):
bravestar = citadels.Structure(1032110505696, type_id=35834)
self.assertEqual(str(bravestar), 'GE-8JV - Mothership Bellicose (1032110505696) - Keepstar')
self.assertTrue(bravestar.accessible)

0 comments on commit bd1321d

Please sign in to comment.