Skip to content

Commit d1e3a0c

Browse files
feat(generator): add test for uv package manager in generator
1 parent 552d1d6 commit d1e3a0c

File tree

1 file changed

+58
-96
lines changed

1 file changed

+58
-96
lines changed

__tests__/app.js

Lines changed: 58 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const GCP_PROJECT_ID = "gcp-project-id";
5555
const GCP_REGION = "us-west1";
5656

5757
const DEFAULT_ANSWERS = {
58+
packageManager: "pyenv + poetry",
5859
pythonVersion: LAST_PYTHON_VERSION,
5960
includeApi: false,
6061
apiInfrastructure: null,
@@ -82,6 +83,9 @@ const GCP_INFRA_ANSWERS = {
8283
gcpProjectId: GCP_PROJECT_ID,
8384
gcpRegion: GCP_REGION
8485
};
86+
const UV_PACKAGE_MANAGER_ANSWERS = {
87+
packageManager: "astral/uv"
88+
};
8589

8690
describe("generator-sicarator:app", () => {
8791
describe.each([
@@ -133,6 +137,11 @@ describe("generator-sicarator:app", () => {
133137
...ALL_OPTIONS_EXCEPT_INFRA_ANSWERS,
134138
...GCP_INFRA_ANSWERS
135139
},
140+
{
141+
description: "uv package manager",
142+
...DEFAULT_ANSWERS,
143+
...UV_PACKAGE_MANAGER_ANSWERS
144+
},
136145
{
137146
description: "Python 3.10 (all options & AWS infra)",
138147
...DEFAULT_ANSWERS,
@@ -143,6 +152,7 @@ describe("generator-sicarator:app", () => {
143152
])(
144153
"Generate project with $description",
145154
({
155+
packageManager,
146156
pythonVersion,
147157
includeApi,
148158
apiInfrastructure,
@@ -160,6 +170,7 @@ describe("generator-sicarator:app", () => {
160170
.run(path.join(__dirname, "../generators/app"))
161171
.withPrompts({
162172
projectName: PROJECT_NAME,
173+
packageManager,
163174
pythonVersion,
164175
includeApi,
165176
apiInfrastructure,
@@ -174,51 +185,26 @@ describe("generator-sicarator:app", () => {
174185
})
175186
.withLocalConfig({})
176187
.on("end", () => {
177-
exec("make install", (error, stdout, stderr) => {
178-
if (stdout) {
179-
console.log(`stdout:\n ${stdout}`);
180-
}
181-
182-
if (stderr) {
183-
console.log(`stderr:\n ${stderr}`);
184-
}
185-
186-
if (error) {
187-
done(error);
188-
} else {
189-
done();
190-
}
191-
});
188+
exec("make install", defaultCallback(done));
192189
});
193190
});
194191

195192
afterAll(done => {
196-
exec(
197-
`pyenv virtualenv-delete --force ${PROJECT_SLUG}`,
198-
(error, stdout, stderr) => {
199-
if (stdout) {
200-
console.log(`stdout:\n ${stdout}`);
201-
}
202-
203-
if (stderr) {
204-
console.log(`stderr:\n ${stderr}`);
205-
}
206-
207-
if (error) {
208-
done(error);
209-
} else {
210-
done();
211-
}
212-
}
213-
);
193+
let cleanVirtualenvCommand =
194+
packageManager === "pyenv + poetry"
195+
? `pyenv virtualenv-delete --force ${PROJECT_SLUG}`
196+
: "rm -rf .venv/";
197+
exec(cleanVirtualenvCommand, defaultCallback(done));
214198
});
215199

216200
it("creates common files", () => {
217201
assert.file(COMMON_FILES_PATHS);
218202
});
219203

220-
it("creates poetry.lock", () => {
221-
assert.file("poetry.lock");
204+
it("creates lock file", () => {
205+
let lockfile =
206+
packageManager === "pyenv + poetry" ? "poetry.lock" : "uv.lock";
207+
assert.file(lockfile);
222208
});
223209

224210
it("creates .gitignore", () => {
@@ -294,7 +280,11 @@ describe("generator-sicarator:app", () => {
294280
});
295281

296282
it("has correct Python version", () => {
297-
assert.fileContent("pyproject.toml", `python = "${pythonVersion}"`);
283+
if (packageManager === "pyenv + poetry") {
284+
assert.fileContent("pyproject.toml", `python = "${pythonVersion}"`);
285+
} else {
286+
assert.fileContent("pyproject.toml", `python = "==${pythonVersion}"`);
287+
}
298288
});
299289

300290
it("has correct terraform backend bucket name", () => {
@@ -327,84 +317,38 @@ describe("generator-sicarator:app", () => {
327317

328318
it("runs unit tests successfully", done => {
329319
if (includeHelloWorld || includeApi || includeStreamlit) {
330-
execInPyenvVenv("make test", (error, stdout, stderr) => {
331-
if (stdout) {
332-
console.log(`stdout:\n ${stdout}`);
333-
}
334-
335-
if (stderr) {
336-
console.log(`stderr:\n ${stderr}`);
337-
}
338-
339-
if (error) {
340-
done(error);
341-
} else {
342-
done();
343-
}
344-
});
320+
execInVenv("make test", packageManager, defaultCallback(done));
345321
} else {
346322
// No tests to run
347323
done();
348324
}
349325
});
350326

351327
it("runs linter successfully", done => {
352-
execInPyenvVenv("make lint-check", (error, stdout, stderr) => {
353-
if (stdout) {
354-
console.log(`stdout:\n ${stdout}`);
355-
}
356-
357-
if (stderr) {
358-
console.log(`stderr:\n ${stderr}`);
359-
}
360-
361-
if (error) {
362-
done(error);
363-
} else {
364-
done();
365-
}
366-
});
328+
execInVenv("make lint-check", packageManager, defaultCallback(done));
367329
});
368330

369331
it("runs type checking successfully", done => {
370-
execInPyenvVenv("make type-check", (error, stdout, stderr) => {
371-
if (stdout) {
372-
console.log(`stdout:\n ${stdout}`);
373-
}
374-
375-
if (stderr) {
376-
console.log(`stderr:\n ${stderr}`);
377-
}
378-
379-
if (error) {
380-
done(error);
381-
} else {
382-
done();
383-
}
384-
});
332+
execInVenv("make type-check", packageManager, defaultCallback(done));
385333
});
386334

387335
it("runs formatting check successfully", done => {
388-
execInPyenvVenv("make format-check", (error, stdout, stderr) => {
389-
if (stdout) {
390-
console.log(`stdout:\n ${stdout}`);
391-
}
392-
393-
if (stderr) {
394-
console.log(`stderr:\n ${stderr}`);
395-
}
396-
397-
if (error) {
398-
done(error);
399-
} else {
400-
done();
401-
}
402-
});
336+
execInVenv("make format-check", packageManager, defaultCallback(done));
403337
});
404338
}
405339
);
406340
});
407341

342+
function execInVenv(command, packageManager, callback) {
343+
if (packageManager === "pyenv + poetry") {
344+
execInPyenvVenv(command, callback);
345+
} else {
346+
exec(command, { env: { ...process.env } }, (error, stdout, stderr) => {
347+
callback(error, stdout, stderr);
348+
});
349+
}
350+
}
351+
408352
function execInPyenvVenv(command, callback) {
409353
// Execute 'pyenv prefix' command to get the venv path
410354
exec("pyenv prefix", (error, stdout, stderr) => {
@@ -436,3 +380,21 @@ function execInPyenvVenv(command, callback) {
436380
);
437381
});
438382
}
383+
384+
function defaultCallback(done) {
385+
return (error, stdout, stderr) => {
386+
if (stdout) {
387+
console.log(`stdout:\n ${stdout}`);
388+
}
389+
390+
if (stderr) {
391+
console.log(`stderr:\n ${stderr}`);
392+
}
393+
394+
if (error) {
395+
done(error);
396+
} else {
397+
done();
398+
}
399+
};
400+
}

0 commit comments

Comments
 (0)