-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement --peru-file, --sync-dir, etc.
Summary: We've been meaning to do this for a while, see #108. Here's the full set: PERU_FILE --peru-file PERU_SYNC_DIR --sync-dir PERU_STATE_DIR --state-dir PERU_CACHE_DIR --cache-dir Note that --peru-file and --sync-dir need to be set together, or not at all; you can't just specify one of them. That's because if you were to set the one that's normally derived from the other (which we could imagine defining in either direction), you end up with weird consequences for the first one that's still derived from the cwd. Test Plan: Several new integration tests. In the process, I found out that we had a few cases where we passed a string instead of a tuple to test helper methods. Added a new assertion to catch those. Reviewers: sean Differential Revision: https://phabricator.buildinspace.com/D210
- Loading branch information
1 parent
22bfe23
commit 6e6ff7c
Showing
7 changed files
with
172 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import os | ||
import textwrap | ||
import unittest | ||
|
||
from peru.compat import makedirs | ||
from peru.error import PrintableError | ||
|
||
import shared | ||
|
||
|
||
class PathsTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.test_root = shared.create_dir() | ||
|
||
self.project_dir = os.path.join(self.test_root, 'project') | ||
self.yaml = textwrap.dedent('''\ | ||
imports: | ||
foo: ./ | ||
cp module foo: | ||
# relative paths should always be interpreted from the dir | ||
# containing peru.yaml, even if that's not the sync dir. | ||
path: ../foo | ||
''') | ||
shared.write_files(self.project_dir, {'peru.yaml': self.yaml}) | ||
self.peru_file = os.path.join(self.project_dir, 'peru.yaml') | ||
|
||
self.foo_dir = os.path.join(self.test_root, 'foo') | ||
shared.write_files(self.foo_dir, {'bar': 'baz'}) | ||
|
||
# We'll run tests from this inner subdirectory, so that we're more | ||
# likely to catch places where we're using the cwd incorrectly. | ||
self.cwd = os.path.join(self.project_dir, 'cwd', 'in', 'here') | ||
makedirs(self.cwd) | ||
|
||
def assert_success(self, sync_dir, state_dir, cache_dir): | ||
shared.assert_contents(sync_dir, {'bar': 'baz'}, | ||
excludes=['.peru', 'peru.yaml']) | ||
assert os.path.isfile(os.path.join(state_dir, 'lastimports')) | ||
assert os.path.isdir(os.path.join(cache_dir, 'trees')) | ||
|
||
def test_unmodified_sync(self): | ||
shared.run_peru_command(['sync'], self.cwd) | ||
self.assert_success(self.project_dir, | ||
os.path.join(self.project_dir, '.peru'), | ||
os.path.join(self.project_dir, '.peru', 'cache')) | ||
|
||
def test_peru_file_and_sync_dir_must_be_set_together(self): | ||
for command, env in [(['--sync-dir=junk', 'sync'], {}), | ||
(['sync'], {'PERU_SYNC_DIR': 'junk'}), | ||
(['--peru-file=junk', 'sync'], {}), | ||
(['sync'], {'PERU_FILE': 'junk'})]: | ||
with self.assertRaises(PrintableError) as e: | ||
shared.run_peru_command(command, cwd=self.cwd, env=env) | ||
assert 'peru file' in e.message and 'sync dir' in e.message | ||
|
||
def test_setting_all_flags(self): | ||
cwd = shared.create_dir() | ||
sync_dir = shared.create_dir() | ||
state_dir = shared.create_dir() | ||
cache_dir = shared.create_dir() | ||
shared.run_peru_command( | ||
['--peru-file', self.peru_file, '--sync-dir', sync_dir, | ||
'--state-dir', state_dir, '--cache-dir', cache_dir, 'sync'], | ||
cwd) | ||
self.assert_success(sync_dir, state_dir, cache_dir) | ||
|
||
def test_setting_all_env_vars(self): | ||
cwd = shared.create_dir() | ||
sync_dir = shared.create_dir() | ||
state_dir = shared.create_dir() | ||
cache_dir = shared.create_dir() | ||
shared.run_peru_command(['sync'], cwd, env={ | ||
'PERU_FILE': self.peru_file, | ||
'PERU_SYNC_DIR': sync_dir, | ||
'PERU_STATE_DIR': state_dir, | ||
'PERU_CACHE_DIR': cache_dir, | ||
}) | ||
self.assert_success(sync_dir, state_dir, cache_dir) | ||
|
||
def test_flags_override_vars(self): | ||
cwd = shared.create_dir() | ||
flag_sync_dir = shared.create_dir() | ||
flag_state_dir = shared.create_dir() | ||
flag_cache_dir = shared.create_dir() | ||
env_sync_dir = shared.create_dir() | ||
env_state_dir = shared.create_dir() | ||
env_cache_dir = shared.create_dir() | ||
shared.run_peru_command( | ||
['--peru-file', self.peru_file, '--sync-dir', flag_sync_dir, | ||
'--state-dir', flag_state_dir, '--cache-dir', flag_cache_dir, | ||
'sync'], | ||
cwd, | ||
env={ | ||
'PERU_FILE': self.peru_file, | ||
'PERU_SYNC_DIR': env_sync_dir, | ||
'PERU_STATE_DIR': env_state_dir, | ||
'PERU_CACHE_DIR': env_cache_dir, | ||
}) | ||
self.assert_success(flag_sync_dir, flag_state_dir, flag_cache_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters