Skip to content

unit tests fail on windows runners #60

@Javagedes

Description

@Javagedes

Hello, unit tests fail on windows runners, specifically for the trailing whitespace tests. This occured for the recent changes made to fix issues with resolving symlinks. The Path call in _normalize_path retains whitespaces on Linux, but removes them on Windows.

A simple (but not elegant) fix I found was to re-apply the trailing whitespace on windows systems.

# At bottom of file
def _count_trailing_whitespace(text: str):
    count = 0
    for char in reversed(str(text)):
        if char.isspace():
            count += 1
        else:
            break
    return count
# In IgnoreRule
def match(self, abs_path):
    """Returns True or False if the path matches the rule."""
    matched = False
    if self.base_path:
        rel_path = str(_normalize_path(abs_path).relative_to(self.base_path))
    else:
        rel_path = str(_normalize_path(abs_path))
    
    # Path() strips trailing spaces on windows
    if sys.platform.startswith('win'):        
        rel_path += " " * _count_trailing_whitespace(abs_path)
    
    # Path() strips the trailing slash, so we need to preserve it
    # in case of directory-only negation
    if self.negation and isinstance(abs_path, str) and abs_path[-1] == '/':
        rel_path += '/'
    if rel_path.startswith('./'):
        rel_path = rel_path[2:]
    if re.search(self.regex, rel_path):
        matched = True
    return matched

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions