You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							66 lines
						
					
					
						
							1.4 KiB
						
					
					
				
			
		
		
	
	
							66 lines
						
					
					
						
							1.4 KiB
						
					
					
				| import shutil | |
| import tempfile | |
| from typing import Dict, List | |
| from pathlib import Path | |
| from dataclasses import dataclass | |
| 
 | |
| import pytest | |
| 
 | |
| 
 | |
| @dataclass | |
| class StubCall: | |
|     func: str | |
|     args: List | |
|     kargs: Dict | |
| 
 | |
| 
 | |
| class StubShell: | |
| 
 | |
|     STDOUT = "STDOUT" | |
| 
 | |
|     def __init__(self): | |
|         self.stack = [] | |
| 
 | |
|     def _add(self, func, args, kargs): | |
|         sc = StubCall(func, args, kargs) | |
|         self.stack.append(sc) | |
| 
 | |
|     def check_call(self, args, **kargs): | |
|         self._add("check_call", args, kargs) | |
| 
 | |
| 
 | |
| @pytest.fixture | |
| def stub_handler(): | |
|     return StubShell() | |
| 
 | |
| 
 | |
| def temporary_data_file(src_data_dir, file_name): | |
|     source = src_data_dir / file_name | |
|     with tempfile.TemporaryDirectory() as tmpdirname: | |
|         destination = Path(tmpdirname) / file_name | |
|         shutil.copy(source, destination) | |
|         yield destination | |
| 
 | |
| 
 | |
| @pytest.fixture | |
| def example_data_dir(): | |
|     this_file = Path(__file__).absolute() | |
|     src_dir = this_file.parent.parent | |
|     return src_dir / "test-data" | |
| 
 | |
| 
 | |
| @pytest.fixture | |
| def example_authz(example_data_dir): | |
|     yield from temporary_data_file(example_data_dir, "authz") | |
| 
 | |
| 
 | |
| @pytest.fixture | |
| def example_htpasswd(example_data_dir): | |
|     yield from temporary_data_file(example_data_dir, "htpasswd") | |
| 
 | |
| 
 | |
| @pytest.fixture | |
| def example_empty_file(): | |
|     with tempfile.TemporaryDirectory() as tmpdirname: | |
|         destination = Path(tmpdirname) / "empty" | |
|         yield destination
 | |
| 
 |