Remove file I/O from tests that don't need it (#11182)

# Description

This PR implements modifications to command tests that write unnecessary
json and csv to disk then load it with open, by using nuon literals
instead.

- Fixes #7189



# User-Facing Changes
None

# Tests + Formatting
This only affects existing tests, which still pass.
This commit is contained in:
Renan Ribeiro
2023-11-29 19:21:34 -03:00
committed by GitHub
parent d08e254d16
commit 54d73748e4
20 changed files with 414 additions and 760 deletions

View File

@ -1,5 +1,3 @@
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
#[test]
@ -43,10 +41,7 @@ fn flatten_nested_tables() {
#[test]
fn flatten_row_column_explicitly() {
Playground::setup("flatten_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"katz.json",
r#"
let sample = r#"
[
{
"people": {
@ -61,24 +56,18 @@ fn flatten_row_column_explicitly() {
}
}
]
"#,
)]);
"#;
let actual = nu!(
cwd: dirs.test(),
"open katz.json | flatten people --all | where name == Andres | length"
);
let actual = nu!(pipeline(&format!(
"{sample} | flatten people --all | where name == Andres | length"
)));
assert_eq!(actual.out, "1");
})
assert_eq!(actual.out, "1");
}
#[test]
fn flatten_row_columns_having_same_column_names_flats_separately() {
Playground::setup("flatten_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"katz.json",
r#"
let sample = r#"
[
{
"people": {
@ -95,24 +84,18 @@ fn flatten_row_columns_having_same_column_names_flats_separately() {
"city": [{"name": "Oregon"}, {"name": "Brooklin"}]
}
]
"#,
)]);
"#;
let actual = nu!(
cwd: dirs.test(),
"open katz.json | flatten --all | flatten people city | get city_name | length"
);
let actual = nu!(pipeline(&format!(
"{sample} | flatten --all | flatten people city | get city_name | length"
)));
assert_eq!(actual.out, "4");
})
assert_eq!(actual.out, "4");
}
#[test]
fn flatten_table_columns_explicitly() {
Playground::setup("flatten_test_3", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"katz.json",
r#"
let sample = r#"
[
{
"people": {
@ -129,24 +112,18 @@ fn flatten_table_columns_explicitly() {
"city": ["Oregon", "Brooklin"]
}
]
"#,
)]);
"#;
let actual = nu!(
cwd: dirs.test(),
"open katz.json | flatten city --all | where people.name == Katz | length"
);
let actual = nu!(pipeline(&format!(
"{sample} | flatten city --all | where people.name == Katz | length",
)));
assert_eq!(actual.out, "2");
})
assert_eq!(actual.out, "2");
}
#[test]
fn flatten_more_than_one_column_that_are_subtables_not_supported() {
Playground::setup("flatten_test_4", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"katz.json",
r#"
let sample = r#"
[
{
"people": {
@ -165,15 +142,10 @@ fn flatten_more_than_one_column_that_are_subtables_not_supported() {
"city": ["Oregon", "Brooklin"]
}
]
"#,
)]);
"#;
let actual = nu!(
cwd: dirs.test(),
"open katz.json | flatten tags city --all"
);
let actual = nu!(pipeline(&format!("{sample} | flatten tags city --all")));
assert!(actual.err.contains("tried flattening"));
assert!(actual.err.contains("but is flattened already"));
})
assert!(actual.err.contains("tried flattening"));
assert!(actual.err.contains("but is flattened already"));
}