def test_default_args(self):
        module1 = ProtoModule([])
        assert module1.sources == []
        assert module1.out_dir == '.'
        assert module1.cwd == '.'
        assert module1.include_dirs == []

        module2 = ProtoModule([])
        assert module1.include_dirs is not module2.include_dirs
 def test_valid_include_dirs(self):
     ProtoModule([],
                 out_dir='.',
                 include_dirs=[
                     'tests',
                     os.path.abspath(os.path.dirname(__file__)),
                 ])
 def test_multiple_module(self, dist):
     with patch('subprocess.check_call') as check_call, \
             patch('distutils.spawn.find_executable') as find_executable:
         find_executable.return_value = 'mock_protoc'
         dist.proto_modules = [
             ProtoModule(['tests/proto/*/*.proto'], cwd='tests/proto'),
             ProtoModule(
                 ['tests/proto/**/*.proto'],
                 out_dir='tests/proto',
                 cwd='tests',
                 include_dirs=['tests/proto/echo'],
             ),
         ]
         build = ProtoBuild(dist)
         build.run()
         assert [call_args[:]
                 for call_args in check_call.call_args_list] == [
                     (
                         ([
                             'mock_protoc',
                             '--python_betterproto_out=.',
                             '-I.',
                             os.path.join('echo', 'echo.proto'),
                         ], ),
                         {
                             'cwd': 'tests/proto'
                         },
                     ),
                     (
                         ([
                             'mock_protoc',
                             '--python_betterproto_out=proto',
                             '-I.',
                             f'-I{os.path.join("proto", "echo")}',
                             os.path.join('proto', 'service.proto'),
                             os.path.join('proto', 'echo', 'echo.proto'),
                         ], ),
                         {
                             'cwd': 'tests'
                         },
                     ),
                 ]
 def test_build(self, dist, capsys):
     with patch('subprocess.check_call') as check_call, \
             patch('distutils.spawn.find_executable') as find_executable:
         find_executable.return_value = 'mock_protoc'
         dist.proto_modules = [
             ProtoModule(['tests/proto/echo/echo.proto'], cwd='tests')
         ]
         build = ProtoBuild(dist)
         build.run()
         assert check_call.call_count == 1
         assert check_call.call_args == (
             ([
                 'mock_protoc',
                 '--python_betterproto_out=.',
                 '-I.',
                 os.path.join('proto', 'echo', 'echo.proto'),
             ], ),
             {
                 'cwd': 'tests'
             },
         )
         captured = capsys.readouterr()
         assert 'Warning' not in captured.out
 def test_nonexist_include_dir(self):
     with pytest.raises(AssertionError) as excinfo:
         ProtoModule([], out_dir='.', include_dirs=['nonexist.dir'])
     assert str(
         excinfo.value) == 'nonexist.dir is not an existing directory.'
 def test_file_as_include_dir(self):
     with pytest.raises(AssertionError) as excinfo:
         ProtoModule([], out_dir='.', include_dirs=['tests/service.proto'])
     assert str(excinfo.value
                ) == 'tests/service.proto is not an existing directory.'
 def test_set_proto_modules(self, dist):
     modules = [ProtoModule([]), ProtoModule([])]
     proto_modules(dist, 'proto_modules', modules)
     assert dist.proto_modules == modules
 def test_set_proto_module(self, dist):
     module = ProtoModule([])
     proto_modules(dist, 'proto_modules', module)
     assert dist.proto_modules == [module]