From a0bc48342ead30a73909f2c8f37bc90bbb7189c5 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Fri, 23 Nov 2018 14:14:08 +0100 Subject: [PATCH] tests: Fix and add tests for west url/revision in manifest After switching from command-line parameters to a special section in the manifest file, rework the tests so that they verify the new scheme of things and add a new invalid manifest that can be tested in order to verify that the schema qualification is working correctly. Signed-off-by: Carles Cufi --- tests/west/manifest/invalid_west_section.yml | 20 ++++++++++ tests/west/manifest/test_manifest.py | 39 ++++++++++++++++++++ tests/west/project/test_project.py | 25 ++++++------- 3 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 tests/west/manifest/invalid_west_section.yml diff --git a/tests/west/manifest/invalid_west_section.yml b/tests/west/manifest/invalid_west_section.yml new file mode 100644 index 0000000..3025daa --- /dev/null +++ b/tests/west/manifest/invalid_west_section.yml @@ -0,0 +1,20 @@ +# The default West manifest file to be used for Zephyr. +# + +west: + url: https://example.com + revision: arevision + invalidfield: thisfieldisinvalid + +manifest: + defaults: + remote: upstream + revision: master + + remotes: + - name: upstream + url: https://example.com + + projects: + - name: zephyr + revision: abranch diff --git a/tests/west/manifest/test_manifest.py b/tests/west/manifest/test_manifest.py index 23a3858..2ec7654 100644 --- a/tests/west/manifest/test_manifest.py +++ b/tests/west/manifest/test_manifest.py @@ -127,6 +127,45 @@ def test_path(): assert manifest.projects[0].path == 'sub/directory' assert manifest.projects[0].abspath == os.path.realpath('/west_top/sub/directory') +def test_sections(): + # Projects must be able to override their default paths. + content_wrong_west = '''\ + west: + url: https://example.com + revision: abranch + wrongfield: avalue + manifest: + remotes: + - name: testremote + url: https://example.com + projects: + - name: testproject + remote: testremote + path: sub/directory + ''' + with patch('west.util.west_topdir', return_value=os.path.realpath('/west_top')): + # Parsing manifest only, no exception raised + manifest = Manifest.from_data(yaml.safe_load(content_wrong_west), 'manifest') + assert manifest.projects[0].path == 'sub/directory' + assert manifest.projects[0].abspath == os.path.realpath('/west_top/sub/directory') + content_wrong_manifest = '''\ + west: + url: https://example.com + revision: abranch + manifest: + remotes: + - name: testremote + url: https://example.com + projects: + - name: testproject + remote: testremote + path: sub/directory + ''' + with patch('west.util.west_topdir', return_value=os.path.realpath('/west_top')): + # Parsing west section only, no exception raised + manifest = Manifest.from_data(yaml.safe_load(content_wrong_manifest), 'west') + assert manifest.westmeta.url == 'https://example.com' + assert manifest.westmeta.revision == 'abranch' # Invalid manifests should raise MalformedManifest. @pytest.mark.parametrize('invalid', diff --git a/tests/west/project/test_project.py b/tests/west/project/test_project.py index cb98b0a..4216715 100644 --- a/tests/west/project/test_project.py +++ b/tests/west/project/test_project.py @@ -294,14 +294,17 @@ def test_update(clean_west_topdir): [manifest] remote = {0}/remote-repos/manifest revision = master - -[west] -remote = {0}/remote-repos/west -revision = master '''.format(clean_west_topdir)) config.read_config() + # modify the manifest to point to another west + clean_west_topdir.join('manifest.yml').write(''' +west: + url: file://{}/remote-repos/west + revision: master +'''.format(clean_west_topdir), 'a') + # Fetch the net-tools repository cmd('fetch --no-update net-tools') @@ -360,16 +363,10 @@ def test_bootstrap_reinit(clean_west_topdir, monkeypatch): bootstrap.init([]) # West already initialized for init_args, west_args in ( - (['-m', 'foo'], ['update', '--reset-manifest', '--reset-projects']), - (['--mr', 'foo'], ['update', '--reset-manifest', '--reset-projects']), - (['-w', 'foo'], ['update', '--reset-west']), - (['--wr', 'foo'], ['update', '--reset-west']), - (['--wr', 'foo'], ['update', '--reset-west']), - (['-m', 'foo', '-w', 'foo'], - ['update', '--reset-manifest', '--reset-projects', '--reset-west']), - (['-b', 'foo'], - ['update', '--reset-manifest', '--reset-projects', '--reset-west']), - (['-b', 'foo', '--no-reset'], [])): + (['-m', 'foo'], ['update', '--reset-manifest', '--reset-projects', + '--reset-west']), + (['--mr', 'foo'], ['update', '--reset-manifest', '--reset-projects', + '--reset-west'])): # Reset wrap_args before each test so that it ends up as [] if wrap() # isn't called (for the --no-reset case)