This guide explains how to test the Type Copy script on different platforms.
pip install pyperclippython test_copy.pyOr with more verbose output:
python test_copy.py -vThe test suite verifies:
- Basic file collection: Scans directories and collects files with matching extensions
- Extension filtering: Only includes files with extensions specified in filename
- Recursive scanning: Processes subdirectories correctly
- Auto-ignore: Skips
.git,node_modules, etc.
- Single folder exclusion:
--exclude test - Multiple folder exclusion:
--exclude test --exclude docs - Short flag:
-e node_modules -e dist - Exclusion messages: Verifies user is informed about excluded paths
- Path handling: Works on Windows (backslash), Unix (forward slash)
- Special characters: Handles spaces and special chars in paths
- Platform detection: Tests run correctly on Windows, macOS, Linux
- No matching files: Proper message when no files match extensions
- Empty directories: Handles directories with no files
- Binary files: Skips binary files automatically
- Pyperclip availability: Verifies clipboard library is installed
- Import checks: Ensures all required modules are available
On Windows, additional tests verify:
- Script runs without "execution policy" errors
- Paths with backslashes work correctly
- Works from Command Prompt and PowerShell
Run Windows-specific tests:
python test_copy.py TestWindowsPermissionsOn macOS:
- Clipboard access via
pbcopyworks - Forward slash paths handled correctly
- Works in Terminal
On Linux:
- Clipboard tools (
xclip,xsel,wl-copy) detected - Forward slash paths handled correctly
- Works in various terminal emulators
Beyond automated tests, manually verify:
- Double-click script (on Windows with
.batfile) - Run from command line
- Check clipboard contains expected content
- Verify file count and size in output
- Exclude one folder
- Exclude multiple folders
- Exclude nested folders
- Verify excluded files not in output
- Rename script to
copy.js.ts.py - Verify only JS/TS files copied
- Rename to
copy.html.css.py - Verify only HTML/CSS files copied
- Run in empty directory
- Run in directory with only excluded folders
- Run with extremely long file paths
- Run with many files (1000+)
For continuous integration, clipboard access might be limited. The test suite handles this gracefully:
# Tests will pass even if clipboard is unavailable
python test_copy.pyTo create a test directory structure:
mkdir -p test_project/{src,dist,node_modules,test}
echo "class Test {}" > test_project/src/test.cs
echo "console.log('hi')" > test_project/src/test.js
echo "# Test" > test_project/README.md
echo "build output" > test_project/dist/app.js
echo "package" > test_project/node_modules/package.jsThen test:
cd test_project
python ../copy.cs.js.py --exclude node_modules --exclude distpip install pyperclipOn Linux/macOS:
chmod +x copy.cs.md.py.pyThis is expected in headless environments. Tests are designed to pass with limited clipboard access.
Increase timeout in test_copy.py:
timeout=30 # Instead of default 10To test performance with large directories:
# Create 1000 test files
for i in {1..1000}; do echo "test $i" > test_$i.py; done
# Time the execution
time python copy.cs.md.py.pyExpected performance:
- 100 files: < 1 second
- 1,000 files: 1-3 seconds
- 10,000 files: 10-30 seconds
To add a new test:
- Open
test_copy.py - Add method to
TestTypeCopyclass:def test_my_feature(self): """Test description""" # Setup self._create_file('test.cs', 'content') # Execute returncode, stdout, stderr = self._run_script(['--my-flag']) # Assert self.assertEqual(returncode, 0) self.assertIn('expected output', stdout)
- Run tests:
python test_copy.py
- Adding new command-line flags
- Changing output format
- Adding new auto-ignore folders
- Modifying exclusion logic
- Windows 10/11
- macOS 11+
- Ubuntu 20.04+
- Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12
Expected output on macOS/Linux:
test_basic_functionality ... ok
test_cross_platform_paths ... ok
test_exclude_multiple_folders ... ok
test_exclude_short_flag ... ok
test_exclude_single_folder ... ok
test_excluded_folder_output_message ... ok
test_no_matching_files ... ok
test_special_characters_in_path ... ok
test_windows_execution_policy ... skipped 'Windows only'
test_pyperclip_import ... ok
----------------------------------------------------------------------
Ran 10 tests in 0.4s
OK (skipped=1)
Expected output on Windows:
test_basic_functionality ... ok
test_cross_platform_paths ... ok
test_exclude_multiple_folders ... ok
test_exclude_short_flag ... ok
test_exclude_single_folder ... ok
test_excluded_folder_output_message ... ok
test_no_matching_files ... ok
test_special_characters_in_path ... ok
test_windows_execution_policy ... ok
test_pyperclip_import ... ok
----------------------------------------------------------------------
Ran 10 tests in 0.5s
OK
All platforms should show "OK" status! ✅