Skip to content

Commit

Permalink
[spellcheck] Part 5: Spell check directories nearcore neard scripts t…
Browse files Browse the repository at this point in the history
…est-utils (#12790)
  • Loading branch information
shreyan-gupta authored Jan 24, 2025
1 parent 6f11ae3 commit 4878e3b
Show file tree
Hide file tree
Showing 21 changed files with 538 additions and 393 deletions.
2 changes: 1 addition & 1 deletion nearcore/src/cold_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ fn cold_store_migration(
hot_store: &Store,
cold_db: Arc<ColdDB>,
) -> anyhow::Result<ColdStoreMigrationResult> {
// Migration is only needed if cold storage is not properly initialised,
// Migration is only needed if cold storage is not properly initialized,
// i.e. if cold head is not set.
if get_cold_head(cold_db.as_ref())?.is_some() {
return Ok(ColdStoreMigrationResult::NoNeedForMigration);
Expand Down
8 changes: 6 additions & 2 deletions nearcore/src/download_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ impl<'a> AutoXzDecoder<'a> {
Some(pos)
} else if pos + len == XZ_HEADER_MAGIC.len() {
let stream = xz2::stream::Stream::new_stream_decoder(u64::max_value(), 0).unwrap();
// TODO(mina86): Once ‘new_uninit’ feature gets stabilised
// replaced buffer initialisation by:
// cspell:ignore uninit
// TODO(mina86): Once ‘new_uninit’ feature gets stabilized
// replaced buffer initialization by:
// let buffer = Box::new_uninit_slice(64 << 10);
// let buffer = unsafe { buffer.assume_init() };
let buffer = vec![0u8; 64 << 10].into_boxed_slice();
Expand Down Expand Up @@ -322,9 +323,11 @@ mod tests {
\x61\xc5\xba\xc5\x84\x00\x00\x00\x89\x4e\xdf\x72\
\x66\xbe\xa9\x51\x00\x01\x32\x1a\x20\x18\x94\x30\
\x1f\xb6\xf3\x7d\x01\x00\x00\x00\x00\x04\x59\x5a";
// cspell:disable-next-line
check_file_download(payload, Ok("Zażółć gęślą jaźń".as_bytes())).await;

let payload = b"\xfd\x37\x7a\x58\x5a\x00A quick brown fox";
// cspell:disable-next-line
check_file_download(payload, Err("Failed to decompress XZ stream: lzma data error")).await;
}

Expand Down Expand Up @@ -415,6 +418,7 @@ mod tests {
\x1f\xb6\xf3\x7d\x01\x00\x00\x00\x00\x04\x59\x5a";
for chunk_size in 1..11 {
let got = auto_xz_test_write_file(buffer, chunk_size).unwrap();
// cspell:disable-next-line
assert_eq!(got, "Zażółć gęślą jaźń".as_bytes());
}
}
Expand Down
4 changes: 2 additions & 2 deletions neard/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn command(prog: &str, args: &[&str], cwd: Option<std::path::PathBuf>) -> Result
/// directory isn’t clean, the version will include `-modified` suffix.
fn get_git_version() -> Result<String> {
// Figure out git directory. Don’t just assume it’s ../.git because that
// doesn’t work with git worktrees so use `git rev-parse --git-dir` instead.
// doesn’t work with git work trees so use `git rev-parse --git-dir` instead.
let pkg_dir = std::path::PathBuf::from(env("CARGO_MANIFEST_DIR")?);
let git_dir = command("git", &["rev-parse", "--git-dir"], Some(pkg_dir));
let git_dir = match git_dir {
Expand All @@ -81,7 +81,7 @@ fn get_git_version() -> Result<String> {

// * --always → if there is no matching tag, use commit hash
// * --dirty=-modified → append ‘-modified’ if there are local changes
// * --tags → consider tags even if they are unnanotated
// * --tags → consider tags even if they are unannotated
// * --match=[0-9]* → only consider tags starting with a digit; this
// prevents tags such as `crates-0.14.0` from being considered
let args = &["describe", "--always", "--dirty=-modified", "--tags", "--match=[0-9]*"];
Expand Down
1 change: 1 addition & 0 deletions neard/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn neard_version() -> Version {

static DEFAULT_HOME: LazyLock<PathBuf> = LazyLock::new(get_default_home);

// cspell:words tikv jemallocator Jemalloc
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

Expand Down
5 changes: 3 additions & 2 deletions nightly/pytest-sanity.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# python sanity tests
# cspell:ignore manytx onetx notx
pytest sanity/simple.py
pytest sanity/simple.py --features nightly
pytest sanity/block_production.py
Expand Down Expand Up @@ -65,8 +66,8 @@ pytest sanity/rpc_missing_block.py
pytest sanity/rpc_missing_block.py --features nightly
pytest --timeout=240 sanity/one_val.py
pytest --timeout=240 sanity/one_val.py nightly --features nightly
pytest --timeout=240 sanity/lightclnt.py
pytest --timeout=240 sanity/lightclnt.py --features nightly
pytest --timeout=240 sanity/lightclient.py
pytest --timeout=240 sanity/lightclient.py --features nightly
pytest sanity/rpc_light_client_execution_outcome_proof.py
pytest sanity/rpc_light_client_execution_outcome_proof.py --features nightly
pytest --timeout=240 sanity/block_sync.py
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions scripts/binary_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ os=$(uname)
arch=$(uname -m)
os_and_arch=${os}-${arch}

# cspell:words czvf
function tar_binary {
mkdir -p $1/${os_and_arch}
cp target/release/$1 $1/${os_and_arch}/
Expand Down
30 changes: 15 additions & 15 deletions scripts/check_nightly.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

import nayduck

IGNORED_SUBDIRS = ('target', 'target_expensive', 'sandbox')
IGNORED_SUBDIRS = ("target", "target_expensive", "sandbox")

EXPENSIVE_DIRECTIVE = 'ultra_slow_test_'
TEST_DIRECTIVE = '#[test]'
EXPENSIVE_DIRECTIVE = "ultra_slow_test_"
TEST_DIRECTIVE = "#[test]"


def expensive_tests_in_file(path: pathlib.Path) -> typing.Iterable[str]:
Expand All @@ -50,7 +50,7 @@ def expensive_tests_in_file(path: pathlib.Path) -> typing.Iterable[str]:
}
Note that anything more complex in the `cfg_attr` will cause the function
not to recognise the test.
not to recognize the test.
Args:
path: Path to the Rust source file.
Expand All @@ -65,11 +65,11 @@ def expensive_tests_in_file(path: pathlib.Path) -> typing.Iterable[str]:
line = line.strip()
if not line:
pass
elif line.startswith('#'):
elif line.startswith("#"):
is_test = is_test or line == TEST_DIRECTIVE
elif line.startswith('fn ultra_slow_test_'):
elif line.startswith("fn ultra_slow_test_"):
if is_test:
match = re.search(r'\bfn\s+([A-Za-z_][A-Za-z_0-9]*)\b',
match = re.search(r"\bfn\s+([A-Za-z_][A-Za-z_0-9]*)\b",
line)
if match:
yield match.group(1)
Expand All @@ -85,8 +85,8 @@ def nightly_tests(repo_dir: pathlib.Path) -> typing.Iterable[str]:
t = test.split()
try:
# It's okay to comment out a test intentionally.
if t[t[0] == '#'] in ('expensive', '#expensive'):
yield t[-1].split('::')[-1]
if t[t[0] == "#"] in ("expensive", "#expensive"):
yield t[-1].split("::")[-1]
except IndexError:
pass

Expand All @@ -100,16 +100,16 @@ def main() -> typing.Optional[str]:
]
path = pathlib.Path(root)
for filename in files:
if filename.endswith('.rs'):
if filename.endswith(".rs"):
filepath = path / filename
print(f'checking file {filepath}')
print(f"checking file {filepath}")
for test in expensive_tests_in_file(filepath):
print(f' expensive test {test}')
print(f" expensive test {test}")
if test not in nightly_txt_tests:
return f'error: file {filepath} test {test} not in nightly.txt'
print('all tests in nightly')
return f"error: file {filepath} test {test} not in nightly.txt"
print("all tests in nightly")
return None


if __name__ == '__main__':
if __name__ == "__main__":
sys.exit(main())
64 changes: 32 additions & 32 deletions scripts/check_pytests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
# test but rather helper scripts and libraries. The entire mocknet/ directory
# is covered here as well since those tests are not run on NayDuck any more.
HELPER_SCRIPTS = [
'delete_remote_nodes.py',
'loadtest/*',
'mocknet/*',
'shardnet/*',
'stress/hundred_nodes/*',
'loadtest/*',
'replay/*',
"delete_remote_nodes.py",
"loadtest/*",
"mocknet/*",
"shardnet/*",
"stress/hundred_nodes/*",
"loadtest/*",
"replay/*",
]

PYTEST_TESTS_DIRECTORY = pathlib.Path('pytest/tests')
PYTEST_TESTS_DIRECTORY = pathlib.Path("pytest/tests")
NIGHTLY_TESTS_FILE = pathlib.Path(nayduck.DEFAULT_TEST_FILE)

# TODO: this should read ci.yml and fetch the list of tests from there
Expand All @@ -47,21 +47,21 @@
StrGenerator = typing.Generator[str, None, None]


def list_test_files(topdir: pathlib.Path) -> StrGenerator:
def list_test_files(top_dir: pathlib.Path) -> StrGenerator:
"""Yields all *.py files in a given directory traversing it recursively.
Args:
topdir: Path to the directory to traverse. Directory is traversed
top_dir: Path to the directory to traverse. Directory is traversed
recursively.
Yields:
Paths (as str objects) to all the Python source files in the directory
relative to the top directory. __init__.py files (and in fact any files
starting with __) are ignored.
"""
for dirname, _, filenames in os.walk(topdir):
dirpath = pathlib.Path(dirname).relative_to(topdir)
for dirname, _, filenames in os.walk(top_dir):
dirpath = pathlib.Path(dirname).relative_to(top_dir)
for filename in filenames:
if not filename.startswith('__') and filename.endswith('.py'):
if not filename.startswith("__") and filename.endswith(".py"):
yield str(dirpath / filename)


Expand All @@ -80,35 +80,35 @@ def read_nayduck_tests(path: pathlib.Path) -> StrGenerator:

def extract_name(line: str) -> StrGenerator:
tokens = line.split()
idx = 1 + (tokens[0] == '#')
while idx < len(tokens) and tokens[idx].startswith('--'):
idx = 1 + (tokens[0] == "#")
while idx < len(tokens) and tokens[idx].startswith("--"):
idx += 1
if idx < len(tokens):
yield tokens[idx]

found_todo = False
for line in nayduck.read_tests_from_file(path, include_comments=True):
line = re.sub(r'\s+', ' ', line.strip())
if re.search(r'^(?:pytest|mocknet) ', line):
line = re.sub(r"\s+", " ", line.strip())
if re.search(r"^(?:pytest|mocknet) ", line):
found_todo = False
yield from extract_name(line)
elif found_todo and re.search(r'^# ?(?:pytest|mocknet) ', line):
elif found_todo and re.search(r"^# ?(?:pytest|mocknet) ", line):
yield from extract_name(line)
elif re.search('^# ?TODO.*#[0-9]{4,}', line):
elif re.search("^# ?TODO.*#[0-9]{4,}", line):
found_todo = True
elif not line.strip().startswith('#'):
elif not line.strip().startswith("#"):
found_todo = False


def print_error(missing: typing.Collection[str]) -> None:
"""Formats and outputs an error message listing missing tests."""
this_file = os.path.relpath(__file__)
example = random.sample(tuple(missing), 1)[0]
if example.startswith('mocknet/'):
example = 'mocknet ' + example
if example.startswith("mocknet/"):
example = "mocknet " + example
else:
example = 'pytest ' + example
msg = '''\
example = "pytest " + example
msg = """\
Found {count} pytest file{s} (i.e. Python file{s} in pytest/tests directory)
which are not included in any of the nightly/*.txt files:
Expand All @@ -129,15 +129,15 @@ def print_error(missing: typing.Collection[str]) -> None:
If the file is not a test but a helper library, consider moving it out
of the pytest/tests directory to pytest/lib or add it to HELPER_SCRIPTS
list at the top of {this_file} file.'''.format(
list at the top of {this_file} file.""".format(
count=len(missing),
s='' if len(missing) == 1 else 's',
missing='\n'.join(
' - pytest/tests/' + name for name in sorted(missing)),
s="" if len(missing) == 1 else "s",
missing="\n".join(
" - pytest/tests/" + name for name in sorted(missing)),
example=example,
this_file=this_file,
todo='TO'
'DO',
todo="TO"
"DO",
)
print(msg, file=sys.stderr)

Expand All @@ -154,9 +154,9 @@ def main() -> int:
if missing:
print_error(missing)
return 1
print(f'All {count} tests included')
print(f"All {count} tests included")
return 0


if __name__ == '__main__':
if __name__ == "__main__":
sys.exit(main())
1 change: 1 addition & 0 deletions scripts/coverage-wrapper-rustc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
## anyway.) Furthermore, instrumenting the crates like these run a risk of significant performance
## regressions, such as seen in #10201

# cspell:words Cinstrument
RUSTC="$1"; shift
exec "$RUSTC" -Cinstrument-coverage --cfg=coverage "$@"
1 change: 1 addition & 0 deletions scripts/fix_nightly_feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def replace_nightly_protocol(deps):
open(toml_file_name, "w").write(new_toml_text)
else:
if new_toml_text != existing_toml_text:
# cspell:words keepends tofile
print("Nightly feature flags need updating:")
sys.stdout.writelines(
difflib.unified_diff(
Expand Down
Loading

0 comments on commit 4878e3b

Please sign in to comment.