Skip to content

Commit

Permalink
fix: Running without options or a config file #281
Browse files Browse the repository at this point in the history
  • Loading branch information
hakancelikdev committed Feb 4, 2023
1 parent 06be1aa commit 955908b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
- id: isort

- repo: https://github.com/hakancelikdev/unimport
rev: 0.14.0
rev: 0.14.1
hooks:
- id: unimport

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inputs:
runs:
using: "composite"
steps:
- run: pip install --upgrade pip && python -m pip install unimport==0.14.0
- run: pip install --upgrade pip && python -m pip install unimport==0.14.1
shell: bash
- run: unimport --color auto --gitignore --ignore-init ${{ inputs.extra_args }}
shell: bash
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased] - YYYY-MM-DD

## [0.14.1] - 2023-02-04

### Fixed

- Running without options or a config file #281.

## [0.14.0] - 2023-02-03

### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/use-with-github-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- name: Check unused imports
uses: hakancelikdev/[email protected].0
uses: hakancelikdev/[email protected].1
with:
extra_args: --include src/
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
# Tools

[tool.pytest.ini_options]
addopts = "-v"
addopts = "--strict-markers"
xfail_strict = true
testpaths = ["tests"]

Expand Down
2 changes: 1 addition & 1 deletion src/unimport/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.14.0"
__version__ = "0.14.1"
__description__ = "A linter, formatter for finding and removing unused import statements."
8 changes: 5 additions & 3 deletions src/unimport/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import configparser
import contextlib
import dataclasses
import functools
import sys
Expand Down Expand Up @@ -191,9 +192,10 @@ def parse_args(cls, args: argparse.Namespace) -> "Config":
config_context = cls(args.config).parse()
elif args.config is None and args.disable_auto_discovery_config is False:
for path in CONFIG_FILES.keys():
config_context = cls(Path(path)).parse()
if config_context:
break
with contextlib.suppress(FileNotFoundError):
config_context = cls(Path(path)).parse()
if config_context:
break

if not config_context:
config_context = None
Expand Down
5 changes: 5 additions & 0 deletions tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,8 @@ def test_use_color_none_of_them():
Config.is_use_color("none-of-them")

assert "none-of-them" in str(cm.value)


@pytest.mark.change_directory("tests/config")
def test_disable_auto_discovery_config_not_found_config_files():
ParseConfig.parse_args(generate_parser().parse_args([]))
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import pytest

Expand All @@ -17,3 +18,20 @@ def logger():
logger.setLevel(level=logging.DEBUG)

return logger


def pytest_configure(config):
config.addinivalue_line("markers", "change_directory(path:str): mark test to change working directory")


def pytest_runtest_setup(item):
for marker in item.iter_markers(name="change_directory"):
item.original_cwd = Path.cwd()

directory = marker.args[0]
os.chdir(directory)


def pytest_runtest_teardown(item, nextitem):
for marker in item.iter_markers(name="change_directory"):
os.chdir(item.original_cwd)

0 comments on commit 955908b

Please sign in to comment.