class CPDBearTest(unittest.TestCase): def setUp(self): self.base_test_path = os.path.abspath( os.path.join(os.path.dirname(__file__), 'code_duplication_samples')) self.section = Section('default') self.section.append(Setting('language', 'java')) self.section.language = Language['Java'] self.queue = Queue() def test_good_file(self): good_file = os.path.join(self.base_test_path, 'good_code.java') with open(good_file) as file: good_filelines = file.readlines() self.uut = CPDBear({good_file: good_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertEqual(result, []) def test_bad_file(self): bad_file = os.path.join(self.base_test_path, 'bad_code.java') with open(bad_file) as file: bad_filelines = file.readlines() self.uut = CPDBear({bad_file: bad_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertNotEqual(result, []) def test_unsupported_language(self): self.section.update_setting(key='language', new_value='html') self.section.language = Language['html'] self.uut = CPDBear({'file_name': 'hello world \n'}, self.section, self.queue) list(self.uut.run_bear_from_section([], {})) self.assertEqual(self.uut.message_queue.queue[0].log_level, logging.ERROR) self.assertIn('Hypertext Markup Language', self.uut.message_queue.queue[0].message) def test_check_prerequisites(self): with mock.patch('bears.general.CPDBear.which') as mock_which: mock_which.side_effect = [None, None, None] self.assertEqual(CPDBear.check_prerequisites(), 'bash is not installed.') mock_which.side_effect = ['path/to/bash', None, None] self.assertEqual( CPDBear.check_prerequisites(), 'PMD is missing. Make sure to install it ' 'from <https://pmd.github.io/>.')
class CPDBearTest(unittest.TestCase): def setUp(self): self.base_test_path = os.path.abspath( os.path.join(os.path.dirname(__file__), 'code_duplication_samples')) self.section = Section('default') self.section.append(Setting('language', 'java')) self.queue = Queue() def test_good_file(self): good_file = os.path.join(self.base_test_path, 'good_code.java') with open(good_file) as file: good_filelines = file.readlines() self.uut = CPDBear({good_file: good_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertEqual(result, []) def test_bad_file(self): bad_file = os.path.join(self.base_test_path, 'bad_code.java') with open(bad_file) as file: bad_filelines = file.readlines() self.uut = CPDBear({bad_file: bad_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertNotEqual(result, [])
def test_check_prerequisites(self): with mock.patch('bears.general.CPDBear.which') as mock_which: mock_which.side_effect = [None, None, None] self.assertEqual(CPDBear.check_prerequisites(), 'bash is not installed.') mock_which.side_effect = ['path/to/bash', None, None] self.assertEqual(CPDBear.check_prerequisites(), 'PMD is missing. Make sure to install it ' 'from <https://pmd.github.io/>.')
def test_bad_file(self): bad_file = os.path.join(self.base_test_path, 'bad_code.java') with open(bad_file) as file: bad_filelines = file.readlines() self.uut = CPDBear({bad_file: bad_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertNotEqual(result, [])
def test_check_prerequisites(self): with mock.patch('bears.general.CPDBear.which') as mock_which: mock_which.side_effect = [None, None, None] self.assertEqual(CPDBear.check_prerequisites(), 'bash is not installed.') mock_which.side_effect = ['path/to/bash', None, None] self.assertEqual( CPDBear.check_prerequisites(), 'PMD is missing. Make sure to install it ' 'from <https://pmd.github.io/>.')
class CPDBearTest(unittest.TestCase): def setUp(self): self.base_test_path = os.path.abspath(os.path.join( os.path.dirname(__file__), 'code_duplication_samples')) self.section = Section('default') self.section.append(Setting('language', 'java')) self.section.language = Language['Java'] self.queue = Queue() def test_good_file(self): good_file = os.path.join(self.base_test_path, 'good_code.java') with open(good_file) as file: good_filelines = file.readlines() self.uut = CPDBear({good_file: good_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertEqual(result, []) def test_bad_file(self): bad_file = os.path.join(self.base_test_path, 'bad_code.java') with open(bad_file) as file: bad_filelines = file.readlines() self.uut = CPDBear({bad_file: bad_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertNotEqual(result, []) def test_unsupported_language(self): self.section.update_setting( key='language', new_value='html') self.section.language = Language['html'] self.uut = CPDBear({'file_name': 'hello world \n'}, self.section, self.queue) list(self.uut.run_bear_from_section([], {})) self.assertEqual( self.uut.message_queue.queue[0].log_level, logging.ERROR) self.assertIn('Hypertext Markup Language', self.uut.message_queue.queue[0].message)
def test_unsupported_language(self): self.section.update_setting(key='language', new_value='html') self.section.language = Language['html'] self.uut = CPDBear({'file_name': 'hello world \n'}, self.section, self.queue) list(self.uut.run_bear_from_section([], {})) self.assertEqual(self.uut.message_queue.queue[0].log_level, logging.ERROR) self.assertIn('Hypertext Markup Language', self.uut.message_queue.queue[0].message)
class CPDBearTest(unittest.TestCase): def setUp(self): self.base_test_path = os.path.abspath(os.path.join( os.path.dirname(__file__), 'code_duplication_samples')) self.section = Section('default') self.section.append(Setting('language', 'java')) self.queue = Queue() def test_good_file(self): good_file = os.path.join(self.base_test_path, 'good_code.java') with open(good_file) as file: good_filelines = file.readlines() self.uut = CPDBear({good_file: good_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertEqual(result, []) def test_bad_file(self): bad_file = os.path.join(self.base_test_path, 'bad_code.java') with open(bad_file) as file: bad_filelines = file.readlines() self.uut = CPDBear({bad_file: bad_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertNotEqual(result, []) def test_unsupported_language(self): self.section.update_setting( key='language', new_value='unsupported_language') self.uut = CPDBear({'file_name': 'hello world \n'}, self.section, self.queue) list(self.uut.run_bear_from_section([], {})) self.assertEqual( self.uut.message_queue.queue[0].log_level, logging.ERROR) self.assertIn('unsupported_language', self.uut.message_queue.queue[0].message)
def test_good_file(self): good_file = os.path.join(self.base_test_path, 'good_code.java') with open(good_file) as file: good_filelines = file.readlines() self.uut = CPDBear({good_file: good_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertEqual(result, [])
class CPDBearTest(unittest.TestCase): def setUp(self): self.base_test_path = os.path.abspath(os.path.join( os.path.dirname(__file__), 'code_duplication_samples')) self.section = Section('default') self.section.append(Setting('language', 'java')) self.queue = Queue() def test_good_file(self): good_file = os.path.join(self.base_test_path, 'good_code.java') with open(good_file) as file: good_filelines = file.readlines() self.uut = CPDBear({good_file: good_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertEqual(result, []) def test_bad_file(self): bad_file = os.path.join(self.base_test_path, 'bad_code.java') with open(bad_file) as file: bad_filelines = file.readlines() self.uut = CPDBear({bad_file: bad_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertNotEqual(result, [])
def test_unsupported_language(self): self.section.update_setting( key='language', new_value='html') self.section.language = Language['html'] self.uut = CPDBear({'file_name': 'hello world \n'}, self.section, self.queue) list(self.uut.run_bear_from_section([], {})) self.assertEqual( self.uut.message_queue.queue[0].log_level, logging.ERROR) self.assertIn('Hypertext Markup Language', self.uut.message_queue.queue[0].message)
class CPDBearTest(unittest.TestCase): def setUp(self): self.base_test_path = os.path.abspath(os.path.join( os.path.dirname(__file__), 'code_duplication_samples')) self.section = Section('default') self.section.append(Setting('language', 'java')) self.section.language = Language['Java'] self.queue = Queue() def test_good_file(self): good_file = os.path.join(self.base_test_path, 'good_code.java') with open(good_file) as file: good_filelines = file.readlines() self.uut = CPDBear({good_file: good_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertEqual(result, []) def test_bad_file(self): bad_file = os.path.join(self.base_test_path, 'bad_code.java') with open(bad_file) as file: bad_filelines = file.readlines() self.uut = CPDBear({bad_file: bad_filelines}, self.section, self.queue) result = list(self.uut.run_bear_from_section([], {})) self.assertNotEqual(result, []) def test_unsupported_language(self): self.section.update_setting( key='language', new_value='html') self.section.language = Language['html'] self.uut = CPDBear({'file_name': 'hello world \n'}, self.section, self.queue) list(self.uut.run_bear_from_section([], {})) self.assertEqual( self.uut.message_queue.queue[0].log_level, logging.ERROR) self.assertIn('Hypertext Markup Language', self.uut.message_queue.queue[0].message) def test_check_prerequisites(self): with mock.patch('bears.general.CPDBear.which') as mock_which: mock_which.side_effect = [None, None, None] self.assertEqual(CPDBear.check_prerequisites(), 'bash is not installed.') mock_which.side_effect = ['path/to/bash', None, None] self.assertEqual(CPDBear.check_prerequisites(), 'PMD is missing. Make sure to install it ' 'from <https://pmd.github.io/>.')