Commit Graph

29 Commits

Author SHA1 Message Date
David Wilson d4897d37bb issue #477: ModuleFinder now returns Unicode module names. 2019-01-25 15:56:06 +00:00
David Wilson 06415bb720 issue #310: fix test failures, teach old import method new tricks
- don't try anything unless something really lives in sys.modules by
  that name
- non-ASCII files are possible
- the unimportable thing might be an extension module, we don't want
  that
2019-01-20 16:46:15 +00:00
David Wilson 6af1a64cce master: handle crazy non-modules in sys.modules again; closes #310. 2019-01-20 15:53:50 +00:00
Alex Willmer 9fbcb67665 Update pytz to 2018.05 (needed by babel 2.6.0)
On Ubuntu 18.04 (others not tested) installing the dev requirements
fails with the following error

babel 2.6.0 has requirement pytz>=0a, but you'll have pytz 2012d which
is incompatible.

Despite the comment in dev_requirements.txt pytz-2012d is not the most
recent version to support Python 2.6. In fact the latest release of pytz
supports Python 2.6.
2018-09-30 21:34:25 +01:00
David Wilson 7697861011 tests: skip one test that triggers bug in ancient vendered six.py 2018-07-07 14:55:47 +01:00
David Wilson c141dd10ec master: fix resolve_relpath()
looks like this was just as broken on 2.x, and suddenly we're
finding a bunch more legit Django deps. It seems anywhere
absolute_import appeared in 2.x, we skipped some imports.
2018-07-07 14:55:47 +01:00
David Wilson b0404bef40 tests: fix get_module_via_* encoding issues 2018-07-07 14:55:47 +01:00
David Wilson 410016ff47 Initial Python 3.x port work.
* ansible: use unicode_literals everywhere since it only needs to be
  compatible back to 2.6.
* compat/collections.py: delete this entirely and rip out the parts of
  functools that require it.
* Introduce serializable Kwargs dict subclass that translates keys to
  Unicode on instantiation.
* enable_debug_logging() must set _v/_vv globals.
* cStringIO does not exist in 3.x.
* Treat IOLogger and LogForwarder input as latin-1.
* Avoid ResourceWarnings in first stage by explicitly closing fps.
* Fix preamble_size.py syntax errors.
2018-07-07 14:55:47 +01:00
David Wilson cec564654e issue #275: tests: fix module_finder_test for 2.6. 2018-06-25 01:36:41 +01:00
David Wilson 4be8afa3d3 issue #275: tests: fix test_simple for 2.6. 2018-06-25 01:36:39 +01:00
David Wilson f7d2eace08 tests: importer fixes 2018-05-29 14:07:13 +01:00
David Wilson 2a4157723a tests: fix breakage from moving is_stdlib_name() 2018-05-08 16:00:59 +01:00
Alex Willmer 1bc32adad4 Issue #160: Cache minimize_source()
Before

```
python tests/bench/local.py
0 120.245933533
1 119.300842285
2 118.355035782
3 123.839855194
```

After

```
python tests/bench/local.py
0 66.3640499115
1 65.9508705139
2 72.4799633026
3 65.7958984375
```
2018-04-07 14:34:41 +01:00
Alex Willmer 491355548d tests: Fix typo in ResolveRelPathTest 2018-03-19 21:58:30 +05:45
Alex Willmer ef35d55523 tests: Remove jinja2/markupsafe modules from FindRelatedTest
Not sure how they got there, but Django doesn't use Jinja without
explicit configuration.
2018-03-19 21:58:30 +05:45
Alex Willmer eee312a57e tests: Fix expected values FindRelatedTest for Django 1.11.4 2018-03-19 21:58:30 +05:45
Alex Willmer 4424bfbb7a tests: Add new FindRelatedImportsTest 2018-03-19 21:58:30 +05:45
Alex Willmer 9e43f5e6ba tests: Remove module under search from expected results
This matches a tweak made in 8765f761c9
2018-03-19 21:58:30 +05:45
Alex Willmer 0f9bfc1e21 tests: Rename FindRelatedImportsTest -> FindRelatedTest 2018-03-19 21:58:30 +05:45
Alex Willmer fa0f390d4d FIx syntax error in FindRelatedImportsTest.test_django_db_models 2018-03-19 21:58:29 +05:45
David Wilson 219718740b Move django test script into permanent test 2018-03-19 21:58:28 +05:45
Alex Willmer 7e01c5bed5 Import and use unittest2 without aliasing it 2018-03-19 21:58:28 +05:45
Alex Willmer e8e023ce59 Use specific TestCase assertions throughout tests
e.g. assert x == y -> self.assertEqual(x, y);
self.assertTrue(isinstance(x, y)) -> self.assertIsInstance(x, y)

These specific methods give more useful errors in the case of a test
failure.
2018-03-19 21:58:28 +05:45
Alex Willmer 17da6e9998 Use unittest2 in all tests
This allows using features such as TestCase,assertIsInstance on Python
2.6 and earlier.
2018-03-19 21:58:27 +05:45
Alex Willmer 3831ac360f Replace all calls to file() with open()
Although these are synonyms in Python 2.x, when using MyPy to typecheck
code use of file() causes spurious errors.

This commit also serves as one small step to Python 3.x compatibility,
since 3.x removes the file() builtin.
2018-03-19 21:58:27 +05:45
Alex Willmer 026669aa93 tests: Fix GetModuleViaPkgutilTest fetching .pyc
On my laptop (Ubuntu 17.10, Python 2.7.14 in a virtualenv),
`test_regular_mod` fails with

```
AssertionError: "\nimport sys\n\n\ndef say_hi():\n    print 'hi'\n" !=
'\x03\xf3\r\n\xbbW\xd5Yc\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00@\x00\x00\x00s\x19\x00\x00\x00d\x00\x00d\x01\x00l\x00\x00Z\x00\x00d\x02\x00\x84\x00\x00Z\x01\x00d\x01\x00S(\x03\x00\x00\x00i\xff\xff\xff\xffNc\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00C\x00\x00\x00s\t\x00\x00\x00d\x01\x00GHd\x00\x00S(\x02\x00\x00\x00Nt\x02\x00\x00\x00hi(\x00\x00\x00\x00(\x00\x00\x00\x00(\x00\x00\x00\x00(\x00\x00\x00\x00sF\x00\x00\x00/home/alex/src/mitogen/tests/data/module_finder_testmod/regular_mod.pyt\x06\x00\x00\x00say_hi\x05\x00\x00\x00s\x02\x00\x00\x00\x00\x01(\x02\x00\x00\x00t\x03\x00\x00\x00sysR\x01\x00\x00\x00(\x00\x00\x00\x00(\x00\x00\x00\x00(\x00\x00\x00\x00sF\x00\x00\x00/home/alex/src/mitogen/tests/data/module_finder_testmod/regular_mod.pyt\x08\x00\x00\x00<module>\x02\x00\x00\x00s\x02\x00\x00\x00\x0c\x03'
```

`__file__` contains the path of the compiled `.pyc`, not the `.py`
source file.
2018-03-19 21:58:27 +05:45
David Wilson 828f60351b importer: Delete _get_module_via_parent entirely
Can't figure out what it's supposed to do any more, and can't find a
version of Ansible before August 2016 (when I wrote that code) that
seems to need it.

Add some more mitigations to avoid sending dylibs.
2018-03-19 21:58:27 +05:45
David Wilson 15bf0f54e2 Beginnings of module_finder_test 2018-03-19 21:35:37 +05:45
David Wilson 2454dcc990 core: loosen assertion to allow fakessh_test to succeed. 2018-03-19 21:35:37 +05:45