Skip to content

Commit ef7b5d6

Browse files
committed
style: clean up whitespace and formatting in test_content_hash.py
1 parent 0306c76 commit ef7b5d6

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

python/cocoindex/tests/test_content_hash.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ def test_content_hash_with_local_files(self):
3535
# Create test files
3636
file1_path = Path(temp_dir) / "test1.txt"
3737
file2_path = Path(temp_dir) / "test2.txt"
38-
38+
3939
file1_content = "This is the content of file 1"
4040
file2_content = "This is the content of file 2"
41-
41+
4242
file1_path.write_text(file1_content)
4343
file2_path.write_text(file2_content)
4444

4545
# Remove database environment variables for this test
4646
with patch.dict(os.environ, {}, clear=False):
4747
for env_var in [
4848
"COCOINDEX_DATABASE_URL",
49-
"COCOINDEX_DATABASE_USER",
49+
"COCOINDEX_DATABASE_USER",
5050
"COCOINDEX_DATABASE_PASSWORD",
5151
]:
5252
os.environ.pop(env_var, None)
@@ -70,15 +70,15 @@ def process_files(
7070
# Test processing files
7171
result1 = process_files.eval(file1_content)
7272
result2 = process_files.eval(file2_content)
73-
73+
7474
assert result1 == f"processed: {file1_content}"
7575
assert result2 == f"processed: {file2_content}"
7676

7777
def test_content_hash_computation(self):
7878
"""Test that content hash is computed correctly."""
7979
# Test content hash computation with known content
8080
test_content = "Hello, World!"
81-
81+
8282
# Remove database environment variables
8383
with patch.dict(os.environ, {}, clear=False):
8484
for env_var in [
@@ -105,7 +105,7 @@ def hash_test_flow(
105105
# Process the same content multiple times
106106
result1 = hash_test_flow.eval(test_content)
107107
result2 = hash_test_flow.eval(test_content)
108-
108+
109109
# Results should be identical for identical content
110110
assert result1 == result2
111111
assert result1 == f"hash_test: {test_content}"
@@ -114,7 +114,7 @@ def test_content_change_detection(self):
114114
"""Test that content change detection works correctly."""
115115
with tempfile.TemporaryDirectory() as temp_dir:
116116
test_file = Path(temp_dir) / "changing_file.txt"
117-
117+
118118
# Initial content
119119
initial_content = "Initial content"
120120
test_file.write_text(initial_content)
@@ -149,7 +149,7 @@ def change_detection_flow(
149149
# Change content and process again
150150
changed_content = "Changed content"
151151
test_file.write_text(changed_content)
152-
152+
153153
result2 = change_detection_flow.eval(changed_content)
154154
assert result2 == f"version: {changed_content}"
155155
assert result1 != result2
@@ -159,12 +159,13 @@ def test_identical_content_different_timestamps(self):
159159
with tempfile.TemporaryDirectory() as temp_dir:
160160
file1 = Path(temp_dir) / "file1.txt"
161161
file2 = Path(temp_dir) / "file2.txt"
162-
162+
163163
content = "Identical content for both files"
164-
164+
165165
# Create files with same content but different timestamps
166166
file1.write_text(content)
167167
import time
168+
168169
time.sleep(0.1) # Small delay to ensure different timestamps
169170
file2.write_text(content)
170171

@@ -194,15 +195,15 @@ def timestamp_test_flow(
194195
# Process both files - should produce identical results
195196
result1 = timestamp_test_flow.eval(content)
196197
result2 = timestamp_test_flow.eval(content)
197-
198+
198199
assert result1 == result2
199200
assert result1 == f"content_hash: {content}"
200201

201202
def test_content_hash_with_binary_data(self):
202203
"""Test content hash functionality with binary data."""
203204
# Create binary test data
204-
binary_data = b'\x00\x01\x02\x03\x04\x05\xff\xfe\xfd'
205-
205+
binary_data = b"\x00\x01\x02\x03\x04\x05\xff\xfe\xfd"
206+
206207
# Remove database environment variables
207208
with patch.dict(os.environ, {}, clear=False):
208209
for env_var in [
@@ -227,9 +228,9 @@ def binary_test_flow(
227228
return content.transform(process_binary_as_text)
228229

229230
# Convert binary to string for processing
230-
text_data = binary_data.decode('latin1') # Use latin1 to preserve all bytes
231+
text_data = binary_data.decode("latin1") # Use latin1 to preserve all bytes
231232
result = binary_test_flow.eval(text_data)
232-
233+
233234
assert f"binary_processed: {len(text_data)} chars" == result
234235

235236
def test_empty_content_hash(self):
@@ -265,7 +266,7 @@ def test_large_content_hash(self):
265266
"""Test content hash with large content."""
266267
# Create large content
267268
large_content = "A" * 10000 + "B" * 10000 + "C" * 10000
268-
269+
269270
# Remove database environment variables
270271
with patch.dict(os.environ, {}, clear=False):
271272
for env_var in [
@@ -297,7 +298,7 @@ def test_unicode_content_hash(self):
297298
"""Test content hash with Unicode content."""
298299
# Create Unicode content with various characters
299300
unicode_content = "Hello 世界! 🌍 Здравствуй мир! مرحبا بالعالم!"
300-
301+
301302
# Remove database environment variables
302303
with patch.dict(os.environ, {}, clear=False):
303304
for env_var in [
@@ -328,7 +329,7 @@ def unicode_flow(
328329
def test_content_hash_consistency(self):
329330
"""Test that content hash is consistent across multiple runs."""
330331
test_content = "Consistency test content"
331-
332+
332333
# Remove database environment variables
333334
with patch.dict(os.environ, {}, clear=False):
334335
for env_var in [
@@ -410,8 +411,12 @@ def hello_world():
410411
@op.function()
411412
def extract_functions(code: str) -> str:
412413
"""Extract function information from code."""
413-
lines = code.strip().split('\n')
414-
functions = [line.strip() for line in lines if line.strip().startswith('def ')]
414+
lines = code.strip().split("\n")
415+
functions = [
416+
line.strip()
417+
for line in lines
418+
if line.strip().startswith("def ")
419+
]
415420
return f"functions: {functions}"
416421

417422
@cocoindex.transform_flow()
@@ -423,19 +428,20 @@ def code_analysis_flow(
423428

424429
# First processing
425430
result1 = code_analysis_flow.eval(content)
426-
431+
427432
# Simulate git checkout by updating file timestamp but keeping same content
428433
import time
434+
429435
time.sleep(0.1)
430436
test_file.write_text(content) # Same content, new timestamp
431437
new_mtime = test_file.stat().st_mtime
432-
438+
433439
# Verify timestamp changed
434440
assert new_mtime > original_mtime
435-
441+
436442
# Second processing - should produce same result due to content hash
437443
result2 = code_analysis_flow.eval(content)
438-
444+
439445
assert result1 == result2
440446
expected = "functions: ['def hello_world():']"
441447
assert result1 == expected
@@ -446,10 +452,10 @@ def test_incremental_processing_simulation(self):
446452
# Create multiple files
447453
files_content = {
448454
"file1.txt": "Content of file 1",
449-
"file2.txt": "Content of file 2",
455+
"file2.txt": "Content of file 2",
450456
"file3.txt": "Content of file 3",
451457
}
452-
458+
453459
file_paths = {}
454460
for filename, content in files_content.items():
455461
file_path = Path(temp_dir) / filename
@@ -498,7 +504,10 @@ def incremental_flow(
498504
# file1 and file3 should have same results (unchanged content)
499505
assert initial_results["file1.txt"] == updated_results["file1.txt"]
500506
assert initial_results["file3.txt"] == updated_results["file3.txt"]
501-
507+
502508
# file2 should have different result (changed content)
503509
assert initial_results["file2.txt"] != updated_results["file2.txt"]
504-
assert updated_results["file2.txt"] == "processed: Modified content of file 2"
510+
assert (
511+
updated_results["file2.txt"]
512+
== "processed: Modified content of file 2"
513+
)

0 commit comments

Comments
 (0)