Skip to content

Commit

Permalink
Ignore global options that are None or set to zero.
Browse files Browse the repository at this point in the history
* Always pop values from task_data to ensure the options are always clean.

This closes #592
  • Loading branch information
hellais committed Aug 29, 2016
1 parent e020064 commit 196fc17
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
16 changes: 10 additions & 6 deletions ooni/deck/deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,16 @@ def __init__(self, data,

self._load(data)

def _get_option(self, name, task_data, default=None):
def _pop_option(self, name, task_data, default=None):
try:
return self.global_options[name]
value = self.global_options[name]
if value in [None, 0]:
raise KeyError
except KeyError:
return task_data.pop(name,
self.parent_metadata.get(name, default))
value = task_data.pop(name,
self.parent_metadata.get(name, default))
task_data.pop(name, None)
return value

def _load_ooni(self, task_data):
required_keys = ["test_name"]
Expand All @@ -334,8 +338,8 @@ def _load_ooni(self, task_data):
nettest_path = nettest_to_path(task_data.pop("test_name"),
self._arbitrary_paths)

annotations = self._get_option('annotations', task_data, {})
collector_address = self._get_option('collector', task_data, None)
annotations = self._pop_option('annotations', task_data, {})
collector_address = self._pop_option('collector', task_data, None)

try:
self.output_path = self.global_options['reportfile']
Expand Down
10 changes: 9 additions & 1 deletion ooni/tests/test_deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ooni import errors
from ooni.deck.store import input_store
from ooni.deck.backend import lookup_collector_and_test_helpers
from ooni.deck.deck import nettest_to_path, NGDeck
from ooni.deck.deck import nettest_to_path, NGDeck, options_to_args
from ooni.deck.legacy import convert_legacy_deck
from ooni.tests.bases import ConfigTestCase
from ooni.tests.mocks import MockBouncerClient, MockCollectorClient
Expand Down Expand Up @@ -330,3 +330,11 @@ def test_convert_legacy_deck(self):
"manipulation/http_header_field_manipulation",
"blocking/web_connectivity"
])
tasks = map(lambda task: task['ooni'], ng_deck['tasks'])
self.assertEqual(
tasks[2]['f'],
'/path/to/citizenlab-urls-global.txt')

def test_options_to_args(self):
args = options_to_args({"f": "foobar.txt", "bar": None, "help": 0})
print(args)
4 changes: 2 additions & 2 deletions ooni/ui/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ def createDeck(global_options, url=None):
raise SystemExit(3)

except errors.OONIUsageError as e:
log.err(e)
print e.net_test_loader.usageOptions().getUsage()
log.exception(e)
map(log.msg, e.net_test_loader.usageOptions().getUsage().split("\n"))
raise SystemExit(4)

except errors.HTTPSCollectorUnsupported:
Expand Down

0 comments on commit 196fc17

Please sign in to comment.