Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed#2591: Replaced os.sep with '/' as it behaves differently on linux and windows. #2630

Merged
merged 1 commit into from
Aug 6, 2017

Conversation

srinivasreddy
Copy link
Contributor

@srinivasreddy srinivasreddy commented Jul 28, 2017

Removed os.sep as it behaves differently linux and windows

  • on linux it is '/'
  • on windows it is '\\'

@srinivasreddy srinivasreddy changed the title remove os.sep as it behaves differently linux and windows. Fixed#2591: Replaced os.sep with '/' as it behaves differently linux and windows. Jul 28, 2017
@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.059% when pulling 7c6d1c9 on srinivasreddy:2591 into 1a9bc14 on pytest-dev:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.059% when pulling 01f0e25 on srinivasreddy:2591 into 1a9bc14 on pytest-dev:master.

@The-Compiler
Copy link
Member

This should have a test, and a changelog entry.

@nicoddemus
Copy link
Member

nicoddemus commented Jul 29, 2017

I agree with @The-Compiler. 👍

To test it, given that this is a somewhat coupled part of the code with the rest of the machinery, I suggest to refactor the loop which identifies the packages/modules of the entrypoint:

         for fn in package_files:
              is_simple_module = '/' not in fn and fn.endswith('.py')
              is_package = fn.count('/') == 1 and fn.endswith('__init__.py')
              if is_simple_module:
                  module_name, ext = os.path.splitext(fn)
                  hook.mark_rewrite(module_name)
              elif is_package:
                  package_name = os.path.dirname(fn)
                  hook.mark_rewrite(package_name)

Into its own function so the above block can become:

for name in iter_rewritable_modules(package_files):
    hook.mark_rewrite(name)

This way you can easily unit-test the logic of iter_rewritable_modules.

@srinivasreddy srinivasreddy changed the title Fixed#2591: Replaced os.sep with '/' as it behaves differently linux and windows. Fixed#2591: Replaced os.sep with '/' as it behaves differently on linux and windows. Jul 29, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 92.064% when pulling eb78410 on srinivasreddy:2591 into 1a9bc14 on pytest-dev:master.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for the new iter_rewritable_modules function

for name in self.iter_rewritable_modules(package_files):
hook.mark_rewrite(name)

def iter_rewritable_modules(self, package_files):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this just need a test 😉

@srinivasreddy
Copy link
Contributor Author

@nicoddemus pointers please. I am new to pytest

@nicoddemus
Copy link
Member

pointers please. I am new to pytest

Sure thing. 👍

I meant that now you can write a proper unit-test along this lines:

@pytest.mark.parametrize('names, expected', [
    (['foo', 'bar.py'], ['foo.bar']),
    (['foo', 'bar.pyc'], []),
    (['foo', '__init__.py'], ['foo']),
    (['foo', 'bar', '__init__.py'], []),
])
def test_iter_rewritable_modules(names, expected):
    from os.path import join
    assert list(iter_rewritable_modules(join(*names) == expected

Note that iter_rewritable_modules can be a function in _pytest/config.py instead of a method because it doesn't need anything from self. (Now I realize it should also be named _iter_rewritable_modules because it is not public)

@nicoddemus
Copy link
Member

This also needs a changelog entry:

Write a file 2591.bugfix in the changelog/ folder with something like:

Correctly consider ``/`` as the file separator to automatically mark plugin files for rewrite on Windows.

module_name, ext = os.path.splitext(fn)
hook.mark_rewrite(module_name)
module_name, _ = os.path.splitext(fn)
modules.append(module_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this an actual generator instead of returning a list, replacing modules.append(module_name) by yield module_name.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 91.824% when pulling 84c7414 on srinivasreddy:2591 into d5f4496 on pytest-dev:master.

* on linux it is '/'

* on windows it is '\'
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 91.824% when pulling a0101f0 on srinivasreddy:2591 into d5f4496 on pytest-dev:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 91.824% when pulling a0101f0 on srinivasreddy:2591 into d5f4496 on pytest-dev:master.

@srinivasreddy
Copy link
Contributor Author

@nicoddemus Please take a look. the build has been passed.

@nicoddemus
Copy link
Member

Thanks @srinivasreddy!

@nicoddemus nicoddemus merged commit 76c55b3 into pytest-dev:master Aug 6, 2017
@srinivasreddy srinivasreddy deleted the 2591 branch August 6, 2017 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants