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

Consolidate API types #1039

Closed
giampaolo opened this issue Apr 30, 2017 · 6 comments
Closed

Consolidate API types #1039

giampaolo opened this issue Apr 30, 2017 · 6 comments

Comments

@giampaolo
Copy link
Owner

From https://github.com/giampaolo/psutil/blob/master/psutil/tests/test_unicode.py:

On Python 3 the returned paths are supposed to match 100% (and this
is tested).
Not on Python 2 though, where we assume correct unicode path handling
is broken. In fact it is broken for most os.* functions, see:
http://bugs.python.org/issue18695
There really is no way for psutil to handle unicode correctly on
Python 2 unless we make such APIs return a unicode type in certain
circumstances.
I'd rather have unicode support broken on Python 2 than having APIs
returning variable str/unicode types, see:
https://github.com/giampaolo/psutil/issues/655#issuecomment-136131180

As such we also test that all APIs on Python 2 always return str and
never unicode (in test_contracts.py).

Basically we assume unicode support is broken on Python 2 and want to make sure unicode is never returned. I added some tests about this (see: 35ebdfb) already.
The only place were we may want to return unicode is WindowsService.description() so this serves as a reminder for that (needs investigation).

Also, I'm adding tests to make sure the same types (int, float, whatever..., see d67154d, 5aa3af3 and test_contracts.py) are returned across across platforms and I already bumped in a couple of errors on OSX but I expect there will be more.

giampaolo added a commit that referenced this issue Apr 30, 2017
… mainly in terms of returned types and API availability
@giampaolo
Copy link
Owner Author

@giampaolo
Copy link
Owner Author

Windows: https://ci.appveyor.com/project/giampaolo/psutil/build/1152/job/s9d2526hkj6ge7g4

======================================================================
FAIL: psutil.tests.test_unicode.TestNonFSAPIS.test_proc_environ
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\projects\psutil\psutil\tests\test_unicode.py", line 271, in test_proc_environ
    self.assertIsInstance(k, str)
AssertionError: u'APPVEYOR_REPO_COMMIT_AUTHOR' is not an instance of <type 'str'>
----------------------------------------------------------------------

@giampaolo
Copy link
Owner Author

giampaolo commented Apr 30, 2017

Windows:

=====================================================================
FAIL: psutil.tests.test_contracts.TestFetchAllProcesses.test_fetch_all
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\users\user\desktop\psutil\psutil\tests\test_contracts.py", line 338, in test_fetch_all
    meth(ret, p)
  File "c:\users\user\desktop\psutil\psutil\tests\test_contracts.py", line 458, in cpu_times
    self.assertIsInstance(n, float)
AssertionError: 0 is not an instance of <type 'float'>

======================================================================
FAIL: psutil.tests.test_contracts.TestSystem.test_net_if_stats
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\users\user\desktop\psutil\psutil\tests\test_contracts.py", line 223, in test_net_if_stats
    self.assertIsInstance(ifname, str)
AssertionError: u'Ethernet 3' is not an instance of <type 'str'>

======================================================================
FAIL: psutil.tests.test_system.TestSystemAPIs.test_net_if_stats
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\users\user\desktop\psutil\psutil\tests\test_system.py", line 642, in test_net_if_stats
    self.assertIsInstance(name, str)
AssertionError: u'Ethernet 3' is not an instance of <type 'str'>

======================================================================
FAIL: psutil.tests.test_unicode.TestNonFSAPIS.test_proc_environ
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\users\user\desktop\psutil\psutil\tests\test_unicode.py", line 270, in test_proc_environ
    self.assertIsInstance(k, str)
AssertionError: u'TMP' is not an instance of <type 'str'>

@giampaolo
Copy link
Owner Author

I will handle this in #1040 as a bigger task. Closing this out as duplicate.

@giampaolo
Copy link
Owner Author

Actually I will handle the str type issue in the other ticket and the rest here.

@giampaolo
Copy link
Owner Author

OK, this should be fixed by now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant