forked from Azure/azure-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interpret the '@' syntax if something higher hasn't already done that. (
- Loading branch information
1 parent
0c0807b
commit 4b9864f
Showing
2 changed files
with
47 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,14 @@ | |
|
||
import unittest | ||
|
||
import os | ||
import tempfile | ||
|
||
from six import StringIO | ||
|
||
from azure.cli.core.application import Application, Configuration, IterateAction | ||
from azure.cli.core.commands import CliCommand | ||
from azure.cli.core._util import CLIError | ||
|
||
class TestApplication(unittest.TestCase): | ||
|
||
|
@@ -80,5 +84,32 @@ def handler(args): | |
self.assertEqual(hellos[1]['hello'], 'sir') | ||
self.assertEqual(hellos[1]['something'], 'else') | ||
|
||
def test_expand_file_prefixed_files(self): | ||
f = tempfile.NamedTemporaryFile(delete=False) | ||
f.close() | ||
|
||
with open(f.name, 'w+') as stream: | ||
stream.write('foo') | ||
|
||
cases = [ | ||
[['--bar=baz'], ['--bar=baz']], | ||
[['--bar', 'baz'], ['--bar', 'baz']], | ||
[['--bar=@{}'.format(f.name)], ['--bar=foo']], | ||
[['--bar', '@{}'.format(f.name)], ['--bar', 'foo']], | ||
[['--bar', f.name], ['--bar', f.name]], | ||
[['--bar="@{}"'.format(f.name)], ['--bar=foo']], | ||
[['[email protected]'], ['[email protected]']], | ||
[['--bar', '[email protected]'], ['--bar', '[email protected]']], | ||
] | ||
|
||
for test_case in cases: | ||
try: | ||
args = Application._expand_file_prefixed_files(test_case[0]) #pylint: disable=protected-access | ||
self.assertEqual(args, test_case[1], 'Failed for: {}'.format(test_case[0])) | ||
except CLIError as ex: | ||
self.fail('Unexpected error for {} ({}): {}'.format(test_case[0], args, ex)) | ||
|
||
os.remove(f.name) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |