Generate arbitrary Config objects.
(**force_strategies: st.SearchStrategy)
| 34 | |
| 35 | |
| 36 | def configs(**force_strategies: st.SearchStrategy) -> st.SearchStrategy: |
| 37 | """Generate arbitrary Config objects.""" |
| 38 | skip = { |
| 39 | "line_ending", |
| 40 | "sections", |
| 41 | "known_future_library", |
| 42 | "forced_separate", |
| 43 | "lines_before_imports", |
| 44 | "lines_after_imports", |
| 45 | "lines_between_sections", |
| 46 | "lines_between_types", |
| 47 | "sources", |
| 48 | "virtual_env", |
| 49 | "conda_env", |
| 50 | "directory", |
| 51 | "formatter", |
| 52 | "formatting_function", |
| 53 | } |
| 54 | inferred_kwargs = { |
| 55 | k: st.from_type(v) |
| 56 | for k, v in get_type_hints(isort.settings._Config).items() |
| 57 | if k not in skip |
| 58 | } |
| 59 | specific = { |
| 60 | "line_length": st.integers(0, 200), |
| 61 | "wrap_length": st.integers(0, 200), |
| 62 | "indent": st.integers(0, 20).map(lambda n: n * " "), |
| 63 | "default_section": st.sampled_from(sorted(isort.settings.KNOWN_SECTION_MAPPING)), |
| 64 | "force_grid_wrap": st.integers(0, 20), |
| 65 | "profile": st.sampled_from(sorted(isort.settings.profiles)), |
| 66 | "py_version": st.sampled_from(("auto", *isort.settings.VALID_PY_TARGETS)), |
| 67 | } |
| 68 | kwargs = {**inferred_kwargs, **specific, **force_strategies} |
| 69 | return st.fixed_dictionaries({}, optional=kwargs).map(_as_config) |
| 70 | |
| 71 | |
| 72 | st.register_type_strategy(isort.Config, configs()) |