| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| |
| import tempfile |
| import textwrap |
| import unittest |
| from pathlib import Path |
| |
| from publish import local_dev_dependency_names |
| from publish import load_manifest |
| from publish import strip_local_dev_dependencies |
| |
| |
| def write(path: Path, content: str) -> None: |
| path.parent.mkdir(parents=True, exist_ok=True) |
| path.write_text(textwrap.dedent(content).strip() + "\n", encoding="utf-8") |
| |
| |
| class ReleaseRustPublishTest(unittest.TestCase): |
| def test_strip_local_dev_dependencies(self): |
| with tempfile.TemporaryDirectory() as tmpdir: |
| root = Path(tmpdir) |
| package = root / "crate" |
| write( |
| package / "Cargo.toml", |
| """ |
| [package] |
| name = "crate" |
| version = "0.1.0" |
| |
| [dependencies] |
| local-normal = { path = "../local-normal", version = "0.1.0" } |
| |
| [dev-dependencies] |
| external-dev = "1" |
| local-dev = { path = "../local-dev", version = "0.1.0" } |
| local-dev-multiline = { path = "../local-dev-multiline", version = "0.1.0", features = [ |
| "test", |
| ] } |
| |
| [target.'cfg(unix)'.dev-dependencies] |
| local-target-dev = { path = "../local-target-dev", version = "0.1.0" } |
| """, |
| ) |
| for name in ( |
| "local-normal", |
| "local-dev", |
| "local-dev-multiline", |
| "local-target-dev", |
| ): |
| (root / name).mkdir() |
| |
| manifest = load_manifest(package / "Cargo.toml") |
| names = local_dev_dependency_names(manifest, package) |
| self.assertEqual( |
| names, |
| {"local-dev", "local-dev-multiline", "local-target-dev"}, |
| ) |
| |
| changed = strip_local_dev_dependencies(package / "Cargo.toml", names) |
| self.assertTrue(changed) |
| |
| stripped = (package / "Cargo.toml").read_text() |
| self.assertIn("local-normal", stripped) |
| self.assertIn("external-dev", stripped) |
| self.assertNotIn("local-dev =", stripped) |
| self.assertNotIn("local-dev-multiline", stripped) |
| self.assertNotIn("local-target-dev", stripped) |
| |
| |
| if __name__ == "__main__": |
| unittest.main() |