Repository: jendrikseipp/vulture

Issue:
Whitelist defaultdict.default_factory
Originally reported by: **bitserver (Bitbucket: [bitserver](https://bitbucket.org/bitserver), GitHub: [bitserver](https://github.com/bitserver))**

----------------------------------------

I have a collections.defaultdict(). After I have finished populating it, I have to set its default_factory attribute to None. vulture then tells me that default_factory is an unused attribute, but I can't help it, as that's how defaultdict works.

----------------------------------------
- Bitbucket: https://bitbucket.org/jendrikseipp/vulture/issue/21


Discussion:
jendrikseipp: The file looks good. Now we only need a test case under `tests/test_whitelist_python.py`. It should check that whitelist_python.py can be run by Python without errors and that code using the `default_factory` attribute is not marked as unused. You can look at `tests/test_script.py` to find out how to test Python files.
RJ722: HI! @jendrikseipp 
Is the current approach in testing (adding an example file and running vulture on it) feasible?

jendrikseipp: This is the only way to test whitelist files. However, normal code 
snippets should be tested in the same way as in `test_scavenging.py`. If 
you're adding multiple tests that belong together, you may consider 
adding a separate test file for that, like `test_format_strings.py`.

RJ722: Thanks! :smile: 

Also, one thing I thought was necessary to bring to your attention was that I have named the example file with a `.txt` extension, because otherwise with the `.py`, it will cause the tests to fail as it would try to run vulture over example file without taking whitelist into consideration!

Also, do we need extra test_cases here?
RJ722: Hi! @jendrikseipp 
Does this looks all right or do we need further enhancements?

Patch:
diff --git a/whitelist_python.py b/whitelist_python.py
new file mode 100644
index 0000000..8e459e6
--- /dev/null
+++ b/whitelist_python.py
@@ -0,0 +1,4 @@
+import collections
+
+collections.defaultdict(list).default_factory = None
+collections.defaultdict(list).default_factory


Test patch:
diff --git a/tests/test_whitelist_python.py b/tests/test_whitelist_python.py
new file mode 100644
index 0000000..3529af0
--- /dev/null
+++ b/tests/test_whitelist_python.py
@@ -0,0 +1,15 @@
+import subprocess
+import sys
+
+from .test_script import call_vulture, REPO
+
+whitelist_file = 'whitelist_python.py'
+
+
+def test_whitelist_python_with_python():
+    assert subprocess.call(
+        [sys.executable, whitelist_file], cwd=REPO) == 0
+
+
+def test_whitelist_python_with_vulture():
+    assert call_vulture([whitelist_file]) == 0