Silence some encoding warnings

By specifiying explicit encodings, we can silence warnings like:

 /__w/meson/meson/test cases/common/100 postconf with args/postconf.py:15: EncodingWarning: 'encoding' argument not specified
  with open(input_file) as f:

in CI.
pull/11583/head
Tristan Partin 2 years ago committed by Dylan Baker
parent bd3d2cf918
commit 3784f72973
  1. 4
      test cases/common/100 postconf with args/postconf.py
  2. 4
      test cases/common/99 postconf/postconf.py
  3. 10
      unittests/allplatformstests.py
  4. 4
      unittests/internaltests.py
  5. 10
      unittests/linuxliketests.py
  6. 4
      unittests/machinefiletests.py
  7. 4
      unittests/platformagnostictests.py

@ -12,7 +12,7 @@ template = '''#pragma once
input_file = os.path.join(os.environ['MESON_SOURCE_ROOT'], 'raw.dat')
output_file = os.path.join(os.environ['MESON_BUILD_ROOT'], 'generated.h')
with open(input_file) as f:
with open(input_file, encoding='utf-8') as f:
data = f.readline().strip()
with open(output_file, 'w') as f:
with open(output_file, 'w', encoding='utf-8') as f:
f.write(template.format(data, sys.argv[1], sys.argv[2]))

@ -10,7 +10,7 @@ template = '''#pragma once
input_file = os.path.join(os.environ['MESON_SOURCE_ROOT'], 'raw.dat')
output_file = os.path.join(os.environ['MESON_BUILD_ROOT'], 'generated.h')
with open(input_file) as f:
with open(input_file, encoding='utf-8') as f:
data = f.readline().strip()
with open(output_file, 'w') as f:
with open(output_file, 'w', encoding='utf-8') as f:
f.write(template.format(data))

@ -2718,7 +2718,7 @@ class AllPlatformTests(BasePlatformTests):
def test_native_dep_pkgconfig(self):
testdir = os.path.join(self.unit_test_dir,
'45 native dep pkgconfig var')
with tempfile.NamedTemporaryFile(mode='w', delete=False) as crossfile:
with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as crossfile:
crossfile.write(textwrap.dedent(
'''[binaries]
pkgconfig = '{}'
@ -2745,7 +2745,7 @@ class AllPlatformTests(BasePlatformTests):
def test_pkg_config_libdir(self):
testdir = os.path.join(self.unit_test_dir,
'45 native dep pkgconfig var')
with tempfile.NamedTemporaryFile(mode='w', delete=False) as crossfile:
with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as crossfile:
crossfile.write(textwrap.dedent(
'''[binaries]
pkgconfig = 'pkg-config'
@ -4196,7 +4196,7 @@ class AllPlatformTests(BasePlatformTests):
cmd = self.meson_command + ['devenv', '-C', self.builddir, '--dump', fname]
o = self._run(cmd)
self.assertEqual(o, '')
o = Path(fname).read_text()
o = Path(fname).read_text(encoding='utf-8')
expected = os.pathsep.join(['/prefix', '$TEST_C', '/suffix'])
self.assertIn(f'TEST_C="{expected}"', o)
self.assertIn('export TEST_C', o)
@ -4697,7 +4697,7 @@ class AllPlatformTests(BasePlatformTests):
testdir = os.path.join(self.unit_test_dir, '102 rlib linkage')
gen_file = os.path.join(testdir, 'lib.rs')
with open(gen_file, 'w') as f:
with open(gen_file, 'w', encoding='utf-8') as f:
f.write(template.format(0))
self.addCleanup(windows_proof_rm, gen_file)
@ -4705,7 +4705,7 @@ class AllPlatformTests(BasePlatformTests):
self.build()
self.run_tests()
with open(gen_file, 'w') as f:
with open(gen_file, 'w', encoding='utf-8') as f:
f.write(template.format(39))
self.build()

@ -453,7 +453,7 @@ class InternalTests(unittest.TestCase):
# Can not be used as context manager because we need to
# open it a second time and this is not possible on
# Windows.
configfile = tempfile.NamedTemporaryFile(mode='w+', delete=False)
configfile = tempfile.NamedTemporaryFile(mode='w+', delete=False, encoding='utf-8')
configfilename = configfile.name
config.write(configfile)
configfile.flush()
@ -469,7 +469,7 @@ class InternalTests(unittest.TestCase):
'needs_exe_wrapper': 'true' if desired_value else 'false'
}
configfile = tempfile.NamedTemporaryFile(mode='w+', delete=False)
configfile = tempfile.NamedTemporaryFile(mode='w+', delete=False, encoding='utf-8')
configfilename = configfile.name
config.write(configfile)
configfile.close()

@ -1024,7 +1024,7 @@ class LinuxlikeTests(BasePlatformTests):
def test_cross_find_program(self):
testdir = os.path.join(self.unit_test_dir, '11 cross prog')
crossfile = tempfile.NamedTemporaryFile(mode='w')
crossfile = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8')
print(os.path.join(testdir, 'some_cross_tool.py'))
tool_path = os.path.join(testdir, 'some_cross_tool.py')
@ -1517,14 +1517,14 @@ class LinuxlikeTests(BasePlatformTests):
def test_identity_cross(self):
testdir = os.path.join(self.unit_test_dir, '60 identity cross')
constantsfile = tempfile.NamedTemporaryFile(mode='w')
constantsfile = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8')
constantsfile.write(textwrap.dedent('''\
[constants]
py_ext = '.py'
'''))
constantsfile.flush()
nativefile = tempfile.NamedTemporaryFile(mode='w')
nativefile = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8')
nativefile.write(textwrap.dedent('''\
[binaries]
c = ['{}' + py_ext]
@ -1532,7 +1532,7 @@ class LinuxlikeTests(BasePlatformTests):
nativefile.flush()
self.meson_native_files = [constantsfile.name, nativefile.name]
crossfile = tempfile.NamedTemporaryFile(mode='w')
crossfile = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8')
crossfile.write(textwrap.dedent('''\
[binaries]
c = ['{}' + py_ext]
@ -1549,7 +1549,7 @@ class LinuxlikeTests(BasePlatformTests):
'CC_FOR_BUILD': '"' + os.path.join(testdir, 'build_wrapper.py') + '"',
'CC': '"' + os.path.join(testdir, 'host_wrapper.py') + '"',
}
crossfile = tempfile.NamedTemporaryFile(mode='w')
crossfile = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8')
crossfile.write('')
crossfile.flush()
self.meson_cross_files = [crossfile.name]

@ -754,7 +754,7 @@ class CrossFileTests(BasePlatformTests):
with tempfile.TemporaryDirectory() as d:
dir_ = os.path.join(d, 'meson', 'cross')
os.makedirs(dir_)
with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False) as f:
with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False, encoding='utf-8') as f:
f.write(cross_content)
name = os.path.basename(f.name)
@ -770,7 +770,7 @@ class CrossFileTests(BasePlatformTests):
with tempfile.TemporaryDirectory() as d:
dir_ = os.path.join(d, '.local', 'share', 'meson', 'cross')
os.makedirs(dir_)
with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False) as f:
with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False, encoding='utf-8') as f:
f.write(cross_content)
name = os.path.basename(f.name)

@ -246,10 +246,10 @@ class PlatformAgnosticTests(BasePlatformTests):
self.init(testdir)
self._run(self.meson_command + ['--internal', 'regenerate', '--profile-self', testdir, self.builddir])
with open(os.path.join(self.builddir, 'meson-logs', 'profile-startup-modules.json')) as f:
with open(os.path.join(self.builddir, 'meson-logs', 'profile-startup-modules.json'), encoding='utf-8') as f:
data = json.load(f)['meson']
with open(os.path.join(testdir, 'expected_mods.json')) as f:
with open(os.path.join(testdir, 'expected_mods.json'), encoding='utf-8') as f:
expected = json.load(f)['meson']['modules']
self.assertEqual(data['modules'], expected)

Loading…
Cancel
Save