Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Tests for class PathStore in lib/path_store.py #214

Merged
merged 9 commits into from
Jun 30, 2015

Conversation

prateshg
Copy link
Contributor


def _setup(self, attrs=None):
def_attrs = {'history_limit': 3}
if attrs:
def_attrs.update(attrs)
path_policy = MagicMock(spec_set=def_attrs.keys())
for k, v in def_attrs.items():
setattr(path_policy, k, v)
return path_policy
pth_str.best_paths_history = []
pth_str.best_paths_history.append([MagicMock(spec_set=['pcb'] for i in range(5)])

  

@prateshg
Copy link
Contributor Author

@kormat Ready for review

@kormat kormat mentioned this pull request Jun 29, 2015
ntools.eq_(pth_str.best_paths_history, "best_paths_history")


class TestPathStoreInit(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is a duplicate

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

class TestPathStoreInit(object):
"""
Unit tests for lib.path_store.PathStore.__init__
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a test for when check_filters returns False

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, i missed test_filters

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one for when check_filters return false "test_filters"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

pcb = MagicMock(spec_set=['get_n_hops'])
pcb.get_n_hops.return_value = 2*i + 2
pth_str.candidates[i].pcb = pcb
pth_str._update_all_hops_length()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check that get_n_hops is called

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

def test_basic(self):
pth_str = PathStore(self._setup())
pth_str.best_paths_history = [1]
pth_str.best_paths_history[0] = [MagicMock(spec_set=['pcb'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit weird. It would be simpler to just do:

pth_str.best_paths_history = []
pth_str.best_paths_history.append([MagicMock(spec_set=['pcb'] for i in range(5)])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kormat
Copy link
Contributor

kormat commented Jun 30, 2015

@prateshg - there's ~5 lines missing from test coverage in this file. If this loads for you, you should be able to see them: https://circle-artifacts.com/gh/netsec-ethz/scion/613/artifacts/0/tmp/circle-artifacts.ylUPwNl/coverage/lib_path_store.html (it's taking ages for me). Otherwise run './scion.sh coverage lib_path_store_test' and then look at the html report that's linked at the bottom of the output.

The affected code is not part of what you're testing here, so i'm happy for you to make a new PR to fix that, and i'll merge this one.

@prateshg
Copy link
Contributor Author

I just looked at those 5 lines. The first 2 are because of the test generator that is used that I will fix. The next 3 are for except in (try/except) so I am not sure do I raise an exception for testing this?

@prateshg
Copy link
Contributor Author

@kormat you can merge this

kormat added a commit that referenced this pull request Jun 30, 2015
Added Tests for class PathStore in lib/path_store.py
@kormat kormat merged commit ac30ed8 into scionproto:master Jun 30, 2015
@kormat
Copy link
Contributor

kormat commented Jun 30, 2015

@prateshg - The test generator has a bug in it, and i'm surprised it didn't fail :(
pth_pol.property_ranges['GuaranteedBandwidth'].extend(range_)
should be:
pth_pol.property_ranges[key].extend(range_)

@kormat
Copy link
Contributor

kormat commented Jun 30, 2015

And yes, for from_file, you should use a test generator to raise all 3 exceptions.

@kormat
Copy link
Contributor

kormat commented Jun 30, 2015

Maybe we're looking at somewhere different, but https://github.com/netsec-ethz/scion/blob/master/test/lib_path_store_test.py#L200 just uses eq_

@kormat
Copy link
Contributor

kormat commented Jun 30, 2015

Ahh. The return of check_property_ranges defaults to True

FR4NK-W pushed a commit to FR4NK-W/osourced-scion that referenced this pull request Feb 14, 2017
Added Tests for class PathStore in lib/path_store.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants