def test_preprocess_include_without_content(self):
     include = pre_ast.Include(
         path='some_path',
         quotes_type='some_quotes_type',
     )
     actual = self.preprocessing_visitor.preprocess(include)
     self.assertIsNone(actual)
 def test_resolve_with_inlcude_and_path_not_exists(self):
     node = pre_ast.Include(
         path='some_path',
         quotes_type='some_quotes_type',
         absolute_path='path_4',
     )
     self.include_linking_visitor.resolve(node, self.files)
     self.assertIsNone(node.content)
Ejemplo n.º 3
0
 def test_collect_includes_with_include(self):
     node = pre_ast.Include(
         path='some_path',
         quotes_type='some_qutes_type',
     )
     actual = self.include_collector.collect_includes(node)
     expected = [node]
     self.assertEqual(actual, expected)
 def test_preprocess_include_with_content(self):
     mock_node = mock.MagicMock()
     include = pre_ast.Include(
         path='some_path',
         quotes_type='some_quotes_type',
         content=mock_node,
     )
     mock_node.accept.return_value = 33
     actual = self.preprocessing_visitor.preprocess(include)
     self.assertEqual(actual, 33)
 def test_parse_include_with_double_quotes(self):
     source = '#include "some/path/to/file_2.h"'
     actual = self.parser.parse(source)
     expected = pre_ast.File(content=pre_ast.CompositeBlock([
         pre_ast.Include(
             path='some/path/to/file_2.h',
             quotes_type=pre_ast.Include.QuotesType.DOUBLE_QUOTES,
         )
     ]))
     self.assertEqual(actual, expected)
 def test_parse_include_with_angle_brackets(self):
     source = '# include <some/path/to/file_1.h>'
     actual = self.parser.parse(source)
     expected = pre_ast.File(content=pre_ast.CompositeBlock([
         pre_ast.Include(
             path='some/path/to/file_1.h',
             quotes_type=pre_ast.Include.QuotesType.ANGLE_BRACKETS,
         )
     ]))
     self.assertEqual(actual, expected)
 def test_load_with_quoted_include_in_the_same_directory(self):
     self.include_directories = [
         'dir_5',
         'dir_6',
     ]
     self.files = {
         'dir_1/dir_2/file_1': 'content_1',
         'dir_1/dir_2/file_4': 'content_4_a',
         'dir_1/dir_3/file_2': 'content_2',
         'dir_1/dir_3/file_4': 'content_4_b',
         'dir_1/dir_4/file_3': 'content_3',
         'dir_1/dir_4/file_4': 'content_4_c',
         'dir_1/file_4': 'content_4_d',
         'dir_5/file_4': 'content_4_e',
         'file_4': 'content_4_f',
     }
     file_1 = mock.MagicMock()
     file_2 = mock.MagicMock()
     file_3 = mock.MagicMock()
     file_4 = mock.MagicMock()
     self.preprocessing_parser.parse.side_effect = (
         file_1,
         file_2,
         file_3,
         file_4,
     )
     include_file_2 = pre_ast.Include(
         path='../dir_3/file_2',
         quotes_type=pre_ast.Include.QuotesType.DOUBLE_QUOTES,
     )
     include_file_3 = pre_ast.Include(
         path='../dir_4/file_3',
         quotes_type=pre_ast.Include.QuotesType.DOUBLE_QUOTES,
     )
     include_file_4 = pre_ast.Include(
         path='file_4',
         quotes_type=pre_ast.Include.QuotesType.DOUBLE_QUOTES,
     )
     self.include_collector.collect_includes.side_effect = (
         [include_file_2],
         [include_file_3],
         [include_file_4],
         [],
     )
     with mock.patch('__builtin__.open', self._mock_open):
         with mock.patch('os.path.isfile', self._mock_isfile):
             actual = self.preprocessing_loader.load(
                 file_path='dir_1/dir_2/file_1',
                 include_directories=self.include_directories,
             )
     expected_parser_calls = [
         mock.call('content_1'),
         mock.call('content_2'),
         mock.call('content_3'),
         mock.call('content_4_c'),
     ]
     self.assertEqual(
         self.preprocessing_parser.parse.call_args_list,
         expected_parser_calls,
     )
     expected_include_collector_calls = [
         mock.call(file_1),
         mock.call(file_2),
         mock.call(file_3),
         mock.call(file_4),
     ]
     self.assertEqual(
         self.include_collector.collect_includes.call_args_list,
         expected_include_collector_calls,
     )
     expected = {
         'dir_1/dir_2/file_1': file_1,
         'dir_1/dir_3/file_2': file_2,
         'dir_1/dir_4/file_3': file_3,
         'dir_1/dir_4/file_4': file_4,
     }
     self.assertEqual(actual, expected)