morganlinton/BeautifulRust / skills/rust-port
rust-port
VerifiedPort code from C, C++, Python, Go, JavaScript, or TypeScript into idiomatic Rust that keeps the original behavior: ownership instead of manual memory, Result instead of error codes and exceptions, enums instead of flag ints and magic strings, and tests that prove the port matches. Use this whenever the user asks to port, translate, convert, migrate, or rewrite code in Rust ("rewrite this in Rust", "what would this look like in Rust", "move this module to Rust"), even if they don't say "port". Pairs with the rust-best-practices skill, which covers the target code's style.
evals/port-python-task-graph/files/test_taskgraph.py
View on GitHubimport unittest
from taskgraph import (
CycleError, MissingDependency, ParseError, TaskError, execution_order,
parse_tasks, summarize,
)
SAMPLE = """
# a small pipeline
compile: build [p=5]
lint: test
unit: test [p=2] <- compile
docs: build
ship: deploy <- unit, lint, docs
"""
class ParseTests(unittest.TestCase):
def test_parses_fields(self):
tasks = parse_tasks(SAMPLE)
self.assertEqual(list(tasks), ["compile", "lint", "unit", "docs", "ship"])
self.assertEqual(tasks["unit"].kind, "test")
self.assertEqual(tasks["unit"].priority, 2)
self.assertEqual(tasks["ship"].deps, ["unit", "lint", "docs"])
self.assertIsNone(tasks["lint"].priority)
def test_negative_priority(self):
self.assertEqual(parse_tasks("a: build [p=-3]")["a"].priority, -3)
def test_parse_errors_report_line(self):
cases = {
"a: build\nnope": 2,
"a: compile": 1,
"a: build\na: test": 2,
"a b: build": 1,
"a: build [p=x]": 1,
"a: build [p=3": 1,
}
for text, line in cases.items():
with self.subTest(text=text):
with self.assertRaises(ParseError) as cm:
parse_tasks(text)
self.assertEqual(cm.exception.line_no, line)
def test_errors_share_a_base_class(self):
self.assertTrue(issubclass(ParseError, TaskError))
self.assertTrue(issubclass(CycleError, TaskError))
self.assertTrue(issubclass(MissingDependency, TaskError))
class OrderTests(unittest.TestCase):
def test_order_respects_deps_and_priority(self):
order = execution_order(parse_tasks(SAMPLE))
self.assertEqual(order, ["compile", "unit", "docs", "lint", "ship"])
def test_missing_dependency(self):
with self.assertRaises(MissingDependency) as cm:
execution_order(parse_tasks("a: build <- ghost"))
self.assertEqual((cm.exception.task, cm.exception.dep), ("a", "ghost"))
def test_cycle_is_named(self):
text = "a: build <- c\nb: build <- a\nc: build <- b\nd: test"
with self.assertRaises(CycleError) as cm:
execution_order(parse_tasks(text))
self.assertEqual(cm.exception.cycle, ["a", "c", "b", "a"])
def test_empty(self):
self.assertEqual(execution_order(parse_tasks("")), [])
class SummaryTests(unittest.TestCase):
def test_counts_every_kind_in_order(self):
self.assertEqual(list(summarize(parse_tasks(SAMPLE)).items()),
[("build", 2), ("test", 2), ("deploy", 1)])
self.assertEqual(summarize({}), {"build": 0, "test": 0, "deploy": 0})
if __name__ == "__main__":
unittest.main()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |