@@ -15511,6 +15511,94 @@ TEST(pipeline_python_nested_helper_keeps_tests_parallel_issue1548) {
1551115511 return pyn_run_nested_helper_tests(52);
1551215512}
1551315513
15514+ /* A decorated class nested in a class body (`@dataclass class Meta:` inside a
15515+ * class) is a nested class like an undecorated one: it gets its Class node and
15516+ * its methods their Method nodes. push_nested_class_nodes looked through
15517+ * field/template/declaration and conditional wrappers but not through Python's
15518+ * decorated_definition, so the decorated class and everything in it was never
15519+ * extracted. Both resolvers. */
15520+ static const char pyn_decorated_nested_py[] = "def deco(cls):\n"
15521+ " return cls\n"
15522+ "\n"
15523+ "class Outer:\n"
15524+ " @deco\n"
15525+ " class Decorated:\n"
15526+ " def run(self):\n"
15527+ " return 1\n"
15528+ "\n"
15529+ " class Plain:\n"
15530+ " def go(self):\n"
15531+ " return 2\n";
15532+
15533+ static bool pyn_node_exists(cbm_store_t *s, const char *project, const char *rel_qn,
15534+ const char *label) {
15535+ char qn[512];
15536+ pyn_qn(qn, sizeof(qn), project, rel_qn);
15537+ cbm_node_t n = {0};
15538+ bool found = cbm_store_find_node_by_qn(s, project, qn, &n) == CBM_STORE_OK && n.label &&
15539+ strcmp(n.label, label) == 0;
15540+ cbm_node_free_fields(&n);
15541+ return found;
15542+ }
15543+
15544+ static int pyn_run_decorated_nested(int fillers) {
15545+ char tmp[256];
15546+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_py_decnest_XXXXXX");
15547+ if (!cbm_mkdtemp(tmp)) {
15548+ FAIL("tmpdir");
15549+ }
15550+ write_temp_file(tmp, "sd.py", pyn_decorated_nested_py);
15551+ for (int i = 0; i < fillers; i++) {
15552+ char name[64];
15553+ char body[128];
15554+ snprintf(name, sizeof(name), "filler%d.py", i);
15555+ snprintf(body, sizeof(body), "def filler%d():\n return %d\n", i, i);
15556+ write_temp_file(tmp, name, body);
15557+ }
15558+ char *old_workers = getenv("CBM_WORKERS");
15559+ char *saved = old_workers ? strdup(old_workers) : NULL;
15560+ if (fillers > 0) {
15561+ cbm_setenv("CBM_WORKERS", "4", 1);
15562+ }
15563+ char db_path[512];
15564+ snprintf(db_path, sizeof(db_path), "%s/decnest.db", tmp);
15565+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
15566+ int rc = p ? cbm_pipeline_run(p) : -1;
15567+ cbm_store_t *s = rc == 0 ? cbm_store_open_path(db_path) : NULL;
15568+ const char *project = p ? cbm_pipeline_project_name(p) : NULL;
15569+ bool dec_class = s && pyn_node_exists(s, project, "sd.Outer.Decorated", "Class");
15570+ bool dec_method = s && pyn_node_exists(s, project, "sd.Outer.Decorated.run", "Method");
15571+ bool plain_class = s && pyn_node_exists(s, project, "sd.Outer.Plain", "Class");
15572+ bool plain_method = s && pyn_node_exists(s, project, "sd.Outer.Plain.go", "Method");
15573+ if (s) {
15574+ cbm_store_close(s);
15575+ }
15576+ if (p) {
15577+ cbm_pipeline_free(p);
15578+ }
15579+ if (saved) {
15580+ cbm_setenv("CBM_WORKERS", saved, 1);
15581+ free(saved);
15582+ } else {
15583+ cbm_unsetenv("CBM_WORKERS");
15584+ }
15585+ th_rmtree(tmp);
15586+ ASSERT_EQ(rc, 0);
15587+ ASSERT_TRUE(dec_class); /* the decorated nested class is extracted */
15588+ ASSERT_TRUE(dec_method); /* ... and its method */
15589+ ASSERT_TRUE(plain_class); /* control: undecorated nested class */
15590+ ASSERT_TRUE(plain_method); /* control */
15591+ PASS();
15592+ }
15593+
15594+ TEST(pipeline_python_decorated_nested_class_extracted) {
15595+ return pyn_run_decorated_nested(0);
15596+ }
15597+
15598+ TEST(pipeline_python_decorated_nested_class_extracted_parallel) {
15599+ return pyn_run_decorated_nested(52);
15600+ }
15601+
1551415602TEST(pipeline_python_project) {
1551515603 /* Port of TestPipelinePythonProject */
1551615604 const char *files[] = {"main.py", "utils.py"};
@@ -25028,6 +25116,8 @@ SUITE(pipeline) {
2502825116 RUN_TEST(pipeline_python_init_function_shares_submodule_qn_parallel_issue1548);
2502925117 RUN_TEST(pipeline_python_nested_helper_keeps_tests_issue1548);
2503025118 RUN_TEST(pipeline_python_nested_helper_keeps_tests_parallel_issue1548);
25119+ RUN_TEST(pipeline_python_decorated_nested_class_extracted);
25120+ RUN_TEST(pipeline_python_decorated_nested_class_extracted_parallel);
2503125121 RUN_TEST(pipeline_header_include_target_is_independent_of_registration_order);
2503225122 RUN_TEST(pipeline_imports_multi_symbol_edges);
2503325123 RUN_TEST(pipeline_go_cross_package_call);
0 commit comments