Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ debug-command: test
# debug-command: test-group

html-demo:
tree_plus https://en.wikipedia.org/wiki/Zero_ring
# tree_plus --yc
python -m tree_plus_cli https://en.wikipedia.org/wiki/Zero_ring
# python -m tree_plus_cli --yc

# test data for the jsonl tokenization
absurdly-huge-jsonl:
Expand Down Expand Up @@ -104,19 +104,19 @@ clean-dist:
rm -rf dist/*

t1:
tree_plus -s -i tests
python -m tree_plus_cli -s -i tests

t2:
tree_plus -s -i group_todo tests/more_languages
python -m tree_plus_cli -s -i group_todo tests/more_languages

t3:
tree_plus -s -g "*.*s" -i group_todo tests/more_languages
python -m tree_plus_cli -s -g "*.*s" -i group_todo tests/more_languages

t4:
tree_plus -s tests/more_languages/group_todo
python -m tree_plus_cli -s tests/more_languages/group_todo

t5:
tree_plus -h
python -m tree_plus_cli -h

t6:
tree_plus -s -c -i group_todo tests/more_languages
python -m tree_plus_cli -s -c -i group_todo tests/more_languages
35 changes: 35 additions & 0 deletions tests/more_languages/group7/test.metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This is a sample Metal file for testing purposes.

#include <metal_stdlib>
using namespace metal;

struct MyData {
float value;
int id;
};

kernel void myKernel(device MyData* data [[buffer(0)]],
uint id [[thread_position_in_grid]]) {
data[id].value *= 2.0;
}

float myHelperFunction(float x, float y) {
return x + y;
}

vertex float4 vertexShader(const device packed_float3* vertex_array [[buffer(0)]],
unsigned int vid [[vertex_id]]) {
return float4(vertex_array[vid], 1.0);
}

fragment half4 fragmentShader(float4 P [[position]]) {
return half4(P.x, P.y, P.z, 1.0);
}

float3 computeNormalMap(ColorInOut in, texture2d<float> normalMapTexture);

float3 computeNormalMap(ColorInOut in, texture2d<float> normalMapTexture) {
float4 encodedNormal = normalMapTexture.sample(nearestSampler, float2(in.texCoord));
float4 normalMap = float4(normalize(encodedNormal.xyz * 2.0 - float3(1,1,1)), 0.0);
return float3(normalize(in.normal * normalMap.z + in.tangent * normalMap.x + in.bitangent * normalMap.y));
}
88 changes: 88 additions & 0 deletions tests/more_languages/group7/test.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Sample WGSL file for testing

alias MyVec = vec4<f32>;
alias AnotherVec = vec2<f32>;

struct VertexInput {
@location(0) position: MyVec,
@location(1) uv: vec2<f32>,
};

struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) uv: vec2<f32>,
};

struct MyUniforms {
mvp: mat4x4<f32>,
color: MyVec,
};

@group(0) @binding(0) var<uniform> u_mvp: mat4x4<f32>;
@group(0) @binding(1) var<uniform> u_color: MyVec;
@group(1) @binding(0) var my_texture: texture_2d<f32>;
@group(1) @binding(1) var my_sampler: sampler;

@vertex
fn vs_main(in: VertexInput) -> VertexOutput {
var out: VertexOutput;
out.position = u_mvp * in.position;
out.uv = in.uv;
return out;
}

@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return u_color * textureSample(my_texture, my_sampler, in.uv);
}

@compute @workgroup_size(8, 8, 1)
fn cs_main(@builtin(global_invocation_id) global_id: vec3<u32>) {
// A simple compute shader example
let x: u32 = global_id.x;
// Do compute work...
}

fn helper_function(val: f32) -> f32 {
return val * 2.0;
}

// Another struct for good measure
struct AnotherStruct {
data: array<f32, 4>,
}


@compute
@workgroup_size(8, 8, 1)
fn multi_line_edge_case(
// Built-in ID, split attribute and name on separate lines
@builtin(global_invocation_id)
globalId : vec3<u32>,

// Texture and sampler with group/binding annotations
@group(1)
@binding(0)
srcTexture : texture_2d<f32>,

@group(1)
@binding(1)
srcSampler : sampler,

// Uniforms block pointer
@group(0)
@binding(0)
uniformsPtr : ptr<uniform, MyUniforms>,

// Optional storage buffer for read/write
storageBuffer : ptr<storage, array<vec4<f32>, 64>, read_write>,
) {
// Compute a flat index
let idx = globalId.x + globalId.y * 8u;

// Sample, tint, and write out
let uv = vec2<f32>(f32(globalId.x) / 8.0, f32(globalId.y) / 8.0);
let tex = textureSample(srcTexture, srcSampler, uv);
let col = uniformsPtr.color * tex;
storageBuffer[idx] = col;
}
43 changes: 26 additions & 17 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import platform
import pytest # noqa: F401
import os
import sys # Added for sys.executable

from rich import print as rich_print

Expand Down Expand Up @@ -38,31 +39,31 @@ def test_tree_plus_on_parent_directory():


def test_tree_plus_help():
result = subprocess.run(["tree_plus", "--help"], capture_output=True, text=True)
result = subprocess.run([sys.executable, "-m", "tree_plus_cli", "--help"], capture_output=True, text=True)
assert result.returncode == 0
assert "Usage: tree_plus" in result.stdout
result = subprocess.run(["tree_plus", "-h"], capture_output=True, text=True)
assert "Usage: tree_plus_cli" in result.stdout # Changed to tree_plus_cli
result = subprocess.run([sys.executable, "-m", "tree_plus_cli", "-h"], capture_output=True, text=True)
assert result.returncode == 0
assert "Usage: tree_plus" in result.stdout
assert "Usage: tree_plus_cli" in result.stdout # Changed to tree_plus_cli


def test_tree_plus_display_version():
from tree_plus_src import __version__

result = subprocess.run(["tree_plus", "-v"], capture_output=True, text=True)
result = subprocess.run([sys.executable, "-m", "tree_plus_cli", "-v"], capture_output=True, text=True)
assert result.returncode == 0
assert __version__ in result.stdout
result = subprocess.run(["tree_plus", "-V"], capture_output=True, text=True)
result = subprocess.run([sys.executable, "-m", "tree_plus_cli", "-V"], capture_output=True, text=True)
assert result.returncode == 0
assert __version__ in result.stdout
result = subprocess.run(["tree_plus", "--version"], capture_output=True, text=True)
result = subprocess.run([sys.executable, "-m", "tree_plus_cli", "--version"], capture_output=True, text=True)
assert result.returncode == 0
assert __version__ in result.stdout


def test_cli_syntax_highlighting_flag():
result = subprocess.run(
["tree_plus", "-d", "tests/path_to_test", "tests/*.py"],
[sys.executable, "-m", "tree_plus_cli", "-d", "tests/path_to_test", "tests/*.py"],
capture_output=True,
text=True,
)
Expand All @@ -80,7 +81,7 @@ def test_cli_syntax_highlighting_flag():
assert " parse_file.py" not in stdout
assert " nested_dir" not in stdout
# result = subprocess.run(
# ["tree_plus", "-d", "-S", "tests/path_to_test", "tests/*.py"],
# [sys.executable, "-m", "tree_plus_cli", "-d", "-S", "tests/path_to_test", "tests/*.py"],
# capture_output=True,
# text=True,
# )
Expand All @@ -98,7 +99,7 @@ def test_cli_syntax_highlighting_flag():
# assert " parse_file.py" not in stdout
# assert " nested_dir" not in stdout
# result = subprocess.run(
# ["tree_plus", "-d", "--syntax", "tests/path_to_test", "tests/*.py"],
# [sys.executable, "-m", "tree_plus_cli", "-d", "--syntax", "tests/path_to_test", "tests/*.py"],
# capture_output=True,
# text=True,
# )
Expand All @@ -119,7 +120,7 @@ def test_cli_syntax_highlighting_flag():

def test_cli_override():
result = subprocess.run(
["tree_plus", "-o", "-i", "*.ini", "tests/dot_dot"],
[sys.executable, "-m", "tree_plus_cli", "-o", "-i", "*.ini", "tests/dot_dot"],
capture_output=True,
text=True,
)
Expand All @@ -134,7 +135,9 @@ def test_cli_override():
# "-i", "*.ini", removed for normal override test
result = subprocess.run(
[
"tree_plus",
sys.executable,
"-m",
"tree_plus_cli",
"-O",
"tests/dot_dot",
],
Expand All @@ -150,7 +153,7 @@ def test_cli_override():
assert " __pycache__" in stdout
assert " test_tp_dotdot.py" in stdout
result = subprocess.run(
["tree_plus", "--override", "-i", ".hypothesis", "tests/dot_dot"],
[sys.executable, "-m", "tree_plus_cli", "--override", "-i", ".hypothesis", "tests/dot_dot"],
capture_output=True,
text=True,
)
Expand All @@ -169,7 +172,7 @@ def test_cli_on_tests():
tests = os.path.join(path_to_tests)
with tree_plus.debug_disabled():
result = subprocess.run(
["tree_plus", "-i", "README.md", tests],
[sys.executable, "-m", "tree_plus_cli", "-i", "README.md", tests],
capture_output=True,
text=True,
)
Expand Down Expand Up @@ -230,12 +233,18 @@ def test_cli_on_folder_with_evil_logging():
folder_with_evil_logging = os.path.join(path_to_tests, "folder_with_evil_logging")
print(folder_with_evil_logging)
with tree_plus.debug_disabled():
# Using sys.executable and -m for robustness, even with shell=True
# The actual command executed by the shell will be constructed carefully.
# Note: shell=True with list args can be tricky.
# It's often better to pass a single string command or ensure the list is correctly interpreted.
# For this specific case, ["python", "-m", "tree_plus_cli", "."] would be more direct if shell wasn't needed
# for other reasons (like cd). But since it's just ".", this should be fine.
cmd = [sys.executable, "-m", "tree_plus_cli", "."]
result = subprocess.run(
["tree_plus", "."],
" ".join(cmd), # Pass as a string if using shell=True and complex commands
capture_output=True,
shell=True,
shell=True,
text=True,
# Set current working directory
cwd=folder_with_evil_logging,
)
print(result)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def test_e2e_ignore_parameter_directory():
def test_e2e_root_rs_glob():
# disable_debug()
# with tree_plus.debug_disabled():
result = tree_plus.from_seed(".", maybe_globs=("*.rs",))
result = tree_plus.from_seed(".", maybe_globs=("*.rs",), concise=True)
result.render()
result_str = result.into_str()
result_lines = result_str.splitlines()
Expand Down
19 changes: 19 additions & 0 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ def test_engine__from_folder_with_ignore_None():
print("\nnormal print: test_engine__from_folder")
# again, ignoring nothing this time
folder_path = Path("tests/dot_dot")

# Ensure the __pycache__ directory exists for the test
# These lines must be indented to be part of the function body (indented from 'def')
pycache_dir = folder_path / "nested_dir" / "__pycache__"
pycache_dir.mkdir(parents=True, exist_ok=True)
dummy_pyc = pycache_dir / "dummy.pyc"
dummy_pyc.touch(exist_ok=True)

tree_plus_no_ignore = engine._from_folder(
folder_path=folder_path,
maybe_ignore=None,
Expand All @@ -166,6 +174,17 @@ def test_engine__from_folder_with_ignore_None():
# does contain ignored things
assert "__pycache__" in no_ignore_tree_string

# Clean up the dummy file and directory if no other .pyc files were generated there
# This is to keep the test environment clean, assuming this test is the sole creator
# or if other .pyc files are not deterministically created.
# For now, let's rely on .gitignore for __pycache__ generally.
# If specific .pyc files were generated by other tests, dummy_pyc.unlink() might fail if it's the same.
# os.remove(dummy_pyc) # This might be problematic if other tests create the same file.
# try:
# pycache_dir.rmdir() # Only removes if empty
# except OSError:
# pass # Not empty, other files exist


def test_engine_amortize_globs():
paths = (Path("tree_plus_src"), Path("tests"))
Expand Down
Loading
Loading