Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wisechengyi committed Dec 25, 2018
1 parent e402adc commit 1911841
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions tests/python/pants_test/task/echo_plugin/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ class EchoTaskBase(HasSkipAndTransitiveGoalOptionsMixin, Task):
prefix = None

def execute(self):
with open(os.path.join(self.workdir, 'output'), 'w') as fp:
fp.write('\n'.join(t.address.spec for t in self.get_targets()))
relevant_targets = self.get_targets()
if relevant_targets:
with open(os.path.join(self.workdir, 'output'), 'w') as fp:
fp.write('\n'.join(t.address.spec for t in relevant_targets))


class EchoOne(EchoTaskBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ def get_echo(which):
return None
else:
with open(path, 'r') as fp:
return [os.path.basename(x.strip()) for x in fp.readlines()]
return {os.path.basename(x.strip()) for x in fp.readlines()}
self.assertEqual(expected_one, get_echo('one'))
self.assertEqual(expected_two, get_echo('two'))

def test_defaults(self):
self._do_test_goal_options([], ['foo:a', 'foo:b'], ['foo:a', 'foo:b'])
self._do_test_goal_options([], {'foo:a', 'foo:b'}, {'foo:a', 'foo:b'})

def test_set_at_goal_level(self):
self._do_test_goal_options(['--skip'], None, None)

def test_set_at_task_level(self):
self._do_test_goal_options(['--echo-one-skip'], None, ['foo:a', 'foo:b'])
self._do_test_goal_options(['--no-echo-two-transitive'], ['foo:a', 'foo:b'], ['foo:a'])
self._do_test_goal_options(['--echo-one-skip'], None, {'foo:a', 'foo:b'})
self._do_test_goal_options(['--no-echo-two-transitive'], {'foo:a', 'foo:b'}, {'foo:a'})

def test_set_at_goal_and_task_level(self):
self._do_test_goal_options(['--skip', '--no-echo-one-skip'], ['foo:a', 'foo:b'], None)
self._do_test_goal_options(['--skip', '--no-echo-one-skip'], {'foo:a', 'foo:b'}, None)
self._do_test_goal_options(['--no-transitive', '--echo-two-transitive'],
['foo:a'], ['foo:a', 'foo:b'])
{'foo:a'}, {'foo:a', 'foo:b'})

0 comments on commit 1911841

Please sign in to comment.