Repository: coala/coala

Issue:
BearTest.py: Fails test because BearTest class needs tearDown method
### Overview Description
BearTest.py will fail on test_download_cached_file if you execute the py.test command more than once.  It fails on line 191 on self.assertFalse(isfile(join(uut.data_dir, filename))). If you clone down the coala repository and install the test-requirements then run py.test, the first time it will pass, but every time after that it will fail.  BearTest class needs a tearDown method, the assert is failing because after the first execution of the tests the file is not being deleted. It passes on the gitmate tests because it uses a fresh run.
 
# Steps to Reproduce

1. Clone coala repository
2. Setup virtual environment and install test-requirements
3. Run py.test (will pass)
4. Run py.test again (will fail)

# Actual Results
self = <tests.bears.BearTest.BearTest testMethod=test_download_cached_file>

	def test_download_cached_file(self):
    	url = 'https://google.com'
    	filename = 'google.html'
    	uut = TestBear(self.settings, None)
>   	self.assertFalse(isfile(join(uut.data_dir, filename)))
E   	AssertionError: True is not false

tests/bears/BearTest.py:191: AssertionError

# Expected Results
No errors.
# Reproducibility

# Additional Information:
I have created a branch called "coala_issue_tearDown" and added a tearDown method while also removing the tear_down method in the TestBear class. The branch seems to fix the issue as far as I have tested.

 https://github.com/jasemj/coala/tree/coala_issue_tearDown

<!-- Hello! If you're filing a bug, please include every step so as to help us reproduce it on our machines. If you're unsure about how to file an issue, use the issue template. If you need any help regarding usage of coala, check out the documentation or hit us up on chat. You can ignore or delete this text, it is commented and won't appear when the issue is submitted or previewed.

Chat: https://coala.io/chat
Issue Template: https://github.com/coala/coala/blob/master/CONTRIBUTING.rst#filing-issues
Documentation: https://docs.coala.io
-->



Discussion:
Hello, I'm wondering if it's possible for me to be assigned this issue once it is verified? Then I can setup a pull request from the branch I have. Unless it is considered a newcomer issue then I will leave it be. Thanks. 
@jasemj Hmmm, I have completely rewritten this code segment in an upcoming pull request #3137 so it is N/A for now. Let me know if the test still fails after the pull is merged. Thanks for the work you have put into finding and fixing this!
@Mixih Okay sounds good, thanks for the quick response. No problem! It's a very cool project and I hope to contribute more. 

Resolving patch:
diff --git a/coalib/bearlib/languages/Language.py b/coalib/bearlib/languages/Language.py
--- a/coalib/bearlib/languages/Language.py
+++ b/coalib/bearlib/languages/Language.py
@@ -5,7 +5,7 @@
 import re
 from operator import itemgetter
 
-from coalib.misc.Annotations import typechain
+from coalib.settings.Annotations import typechain
 
 
 class LanguageUberMeta(type):
diff --git a/coalib/misc/Annotations.py b/coalib/settings/Annotations.py
similarity index 100%
rename from coalib/misc/Annotations.py
rename to coalib/settings/Annotations.py


Test patch:
diff --git a/docs/Developers/Testing_Bears.rst b/docs/Developers/Testing_Bears.rst
--- a/docs/Developers/Testing_Bears.rst
+++ b/docs/Developers/Testing_Bears.rst
@@ -42,7 +42,7 @@ Let us understand how to write tests for ``TooManyLinesBear`` in ``some_dir``.
 .. code::
 
     from bears.some_dir.TooManyLinesBear import TooManyLinesBear
-    from tests.LocalBearTestHelper import verify_local_bear
+    from coalib.testing.LocalBearTestHelper import verify_local_bear
 
     good_file = '1\n2\n3\n4\n'.splitlines()
     bad_file = '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n'.splitlines()
@@ -71,7 +71,7 @@ arguments.
     from queue import Queue
     from bears.some_dir.TooManyLinesBear import TooManyLinesBear
 
-    from tests.LocalBearTestHelper import LocalBearTestHelper
+    from coalib.testing.LocalBearTestHelper import LocalBearTestHelper
     from coalib.settings.Section import Section
     from coalib.settings.Setting import Setting
 
@@ -110,7 +110,7 @@ passed.
     from queue import Queue
 
     from bears.some_dir.TooManyLinesBear import TooManyLinesBear
-    from tests.LocalBearTestHelper import LocalBearTestHelper
+    from coalib.testing.LocalBearTestHelper import LocalBearTestHelper
     from coalib.results.Result import Result
     from coalib.settings.Section import Section
 
diff --git a/tests/bears/BearTest.py b/tests/bears/BearTest.py
--- a/tests/bears/BearTest.py
+++ b/tests/bears/BearTest.py
@@ -1,6 +1,6 @@
 import multiprocessing
 import unittest
-from os.path import abspath, isfile, join, getmtime
+from os.path import abspath, exists, isfile, join, getmtime
 import shutil
 
 from coalib.bears.Bear import Bear
@@ -32,9 +32,6 @@ def run(self):
         self.err('teardown')
         self.err()
 
-    def tear_down(self):
-        shutil.rmtree(self.data_dir)
-
 
 class TypedTestBear(Bear):
 
@@ -71,6 +68,10 @@ def setUp(self):
         self.settings = Section('test_settings')
         self.uut = TestBear(self.settings, self.queue)
 
+    def tearDown(self):
+        if exists(self.uut.data_dir):
+            shutil.rmtree(self.uut.data_dir)
+
     def test_simple_api(self):
         self.assertRaises(TypeError, TestBear, self.settings, 2)
         self.assertRaises(TypeError, TestBear, None, self.queue)
@@ -187,13 +188,12 @@ def test_new_result(self):
     def test_download_cached_file(self):
         url = 'https://google.com'
         filename = 'google.html'
-        uut = TestBear(self.settings, None)
-        self.assertFalse(isfile(join(uut.data_dir, filename)))
-        expected_filename = join(uut.data_dir, filename)
-        result_filename = uut.download_cached_file(url, filename)
+        self.assertFalse(isfile(join(self.uut.data_dir, filename)))
+        expected_filename = join(self.uut.data_dir, filename)
+        result_filename = self.uut.download_cached_file(url, filename)
         self.assertEqual(result_filename, expected_filename)
-        expected_time = getmtime(join(uut.data_dir, filename))
-        result_filename = uut.download_cached_file(url, filename)
+        expected_time = getmtime(join(self.uut.data_dir, filename))
+        result_filename = self.uut.download_cached_file(url, filename)
         self.assertEqual(result_filename, expected_filename)
-        result_time = getmtime(join(uut.data_dir, filename))
+        result_time = getmtime(join(self.uut.data_dir, filename))
         self.assertEqual(result_time, expected_time)
diff --git a/tests/misc/AnnotationsTest.py b/tests/settings/AnnotationsTest.py
similarity index 97%
rename from tests/misc/AnnotationsTest.py
rename to tests/settings/AnnotationsTest.py
--- a/tests/misc/AnnotationsTest.py
+++ b/tests/settings/AnnotationsTest.py
@@ -1,6 +1,6 @@
 from unittest import TestCase
 
-from coalib.misc.Annotations import typechain
+from coalib.settings.Annotations import typechain
 
 
 class AnnotationsTest(TestCase):