[bitbake-devel] [RFC][PATCH v2 3/3] tests/fetch.py: add npm tests
Mark Hatle
mark.hatle at kernel.crashing.org
Fri Oct 25 18:27:59 UTC 2019
The only test(s) I see missing are the "NoNetwork" tests.
I.e. you should fetch/download a know item, and then verify it ends up in the
DL_DIR in the "correct" format.
Then a second test (with BB_NO_NETWORK = "1") both a positive and negative test.
Negative - try to fetch something from the network and verify it fails.
Positive - use the DL_DIR version (from above) and verify the local version is
re-used, no network is used.
Otherwise the testing looks good to me. (I don't know enough about the
particular NPM steps to review the other parts.)
--Mark
On 10/25/19 3:39 AM, Jean-Marie LEMETAYER wrote:
> This commit adds some basic tests for the npm fetcher.
>
> Signed-off-by: Jean-Marie LEMETAYER <jean-marie.lemetayer at savoirfairelinux.com>
> ---
> lib/bb/tests/fetch.py | 82 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 82 insertions(+)
>
> diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
> index a0b656b6..781226d2 100644
> --- a/lib/bb/tests/fetch.py
> +++ b/lib/bb/tests/fetch.py
> @@ -1988,3 +1988,85 @@ class GitLfsTest(FetcherTest):
> ud.method._find_git_lfs = lambda d: False
> shutil.rmtree(self.gitdir, ignore_errors=True)
> fetcher.unpack(self.d.getVar('WORKDIR'))
> +
> +class NPMTest(FetcherTest):
> + def skipIfNoNpm():
> + import shutil
> + if not shutil.which('npm'):
> + return unittest.skip('npm not installed, tests being skipped')
> + return lambda f: f
> +
> + @skipIfNoNpm()
> + @skipIfNoNetwork()
> + def test_npm(self):
> + url = 'npm://registry.npmjs.org;name=@savoirfairelinux/node-server-example;version=1.0.0'
> + fetcher = bb.fetch.Fetch([url], self.d)
> + fetcher.download()
> + fetcher.unpack(self.unpackdir)
> + unpackdir = os.path.join(self.unpackdir, 'npm')
> + self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
> +
> + @skipIfNoNpm()
> + @skipIfNoNetwork()
> + def test_npm_registry_alternate(self):
> + url = 'npm://registry.freajs.org;name=@savoirfairelinux/node-server-example;version=1.0.0'
> + fetcher = bb.fetch.Fetch([url], self.d)
> + fetcher.download()
> + fetcher.unpack(self.unpackdir)
> + unpackdir = os.path.join(self.unpackdir, 'npm')
> + self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
> +
> + @skipIfNoNpm()
> + @skipIfNoNetwork()
> + def test_npm_version_latest(self):
> + url = 'npm://registry.npmjs.org;name=@savoirfairelinux/node-server-example;version=latest'
> + fetcher = bb.fetch.Fetch([url], self.d)
> + fetcher.download()
> + fetcher.unpack(self.unpackdir)
> + unpackdir = os.path.join(self.unpackdir, 'npm')
> + self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
> +
> + @skipIfNoNpm()
> + @skipIfNoNetwork()
> + def test_npm_registry_invalid(self):
> + url = 'npm://registry.invalid.org;name=@savoirfairelinux/node-server-example;version=1.0.0'
> + fetcher = bb.fetch.Fetch([url], self.d)
> + with self.assertRaises(bb.fetch2.FetchError):
> + fetcher.download()
> +
> + @skipIfNoNpm()
> + @skipIfNoNetwork()
> + def test_npm_name_invalid(self):
> + url = 'npm://registry.npmjs.org;name=@savoirfairelinux/invalid;version=1.0.0'
> + fetcher = bb.fetch.Fetch([url], self.d)
> + with self.assertRaises(bb.fetch2.FetchError):
> + fetcher.download()
> +
> + @skipIfNoNpm()
> + @skipIfNoNetwork()
> + def test_npm_version_invalid(self):
> + url = 'npm://registry.npmjs.org;name=@savoirfairelinux/node-server-example;version=invalid'
> + fetcher = bb.fetch.Fetch([url], self.d)
> + with self.assertRaises(bb.fetch2.FetchError):
> + fetcher.download()
> +
> + @skipIfNoNpm()
> + @skipIfNoNetwork()
> + def test_npm_registry_none(self):
> + url = 'npm://;name=@savoirfairelinux/node-server-example;version=1.0.0'
> + with self.assertRaises(bb.fetch2.MalformedUrl):
> + fetcher = bb.fetch.Fetch([url], self.d)
> +
> + @skipIfNoNpm()
> + @skipIfNoNetwork()
> + def test_npm_name_none(self):
> + url = 'npm://registry.npmjs.org;version=1.0.0'
> + with self.assertRaises(AttributeError):
> + fetcher = bb.fetch.Fetch([url], self.d)
> +
> + @skipIfNoNpm()
> + @skipIfNoNetwork()
> + def test_npm_version_none(self):
> + url = 'npm://registry.npmjs.org;name=@savoirfairelinux/node-server-example'
> + with self.assertRaises(AttributeError):
> + fetcher = bb.fetch.Fetch([url], self.d)
>
More information about the bitbake-devel
mailing list