Fixes #23680 bug with py3.x due to binary string handling (#23688)

* This commit includes a unit test to exercise the _is_role
function and make sure it doesn't break in any Python version.
* Import os.path and other minor fixups
This commit is contained in:
Miguel Ángel Ajo 2017-09-10 03:40:07 +02:00 committed by Toshio Kuratomi
parent 0274835add
commit 8e4f112b39
2 changed files with 18 additions and 23 deletions

View file

@ -41,6 +41,12 @@ class TestDataLoader(unittest.TestCase):
def tearDown(self):
pass
@patch('os.path.exists')
def test__is_role(self, p_exists):
p_exists.side_effect = lambda p: p == b'test_path/tasks/main.yml'
self.assertTrue(self._loader._is_role('test_path/tasks'))
self.assertTrue(self._loader._is_role('test_path/'))
@patch.object(DataLoader, '_get_file_contents')
def test_parse_json_from_file(self, mock_def):
mock_def.return_value = (b"""{"a": 1, "b": 2, "c": 3}""", True)