mirror of
https://github.com/chenxiaolong/avbroot.git
synced 2026-07-03 14:05:11 +02:00
Use unittest.mock.patch for replacing classes and variables
The mechanism is still the same (modifies global state), but the code is a bit cleaner. Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
This commit is contained in:
+3
-8
@@ -10,6 +10,7 @@ import os
|
||||
import struct
|
||||
import sys
|
||||
import subprocess
|
||||
import unittest.mock
|
||||
import zipfile
|
||||
|
||||
# Silence undesired warning
|
||||
@@ -758,12 +759,6 @@ def match_android_zip64_limit():
|
||||
[1] https://cs.android.com/android/platform/superproject/+/android-13.0.0_r18:system/libziparchive/zip_archive.cc;l=692
|
||||
'''
|
||||
|
||||
orig_limit = zipfile.ZIP64_LIMIT
|
||||
|
||||
try:
|
||||
# Because Python uses > and Android uses >= 0xffffffff
|
||||
zipfile.ZIP64_LIMIT = 0xfffffffe
|
||||
|
||||
# Because Python uses > and Android uses >= 0xffffffff
|
||||
with unittest.mock.patch('zipfile.ZIP64_LIMIT', 0xfffffffe):
|
||||
yield
|
||||
finally:
|
||||
zipfile.ZIP64_LIMIT = orig_limit
|
||||
|
||||
+3
-7
@@ -1,4 +1,5 @@
|
||||
import contextlib
|
||||
import unittest.mock
|
||||
|
||||
import avbtool
|
||||
|
||||
@@ -26,14 +27,9 @@ def smuggle_descriptors():
|
||||
* call encode on each descriptor
|
||||
'''
|
||||
|
||||
orig_kernel = avbtool.AvbKernelCmdlineDescriptor
|
||||
|
||||
avbtool.AvbKernelCmdlineDescriptor = SmuggledViaKernelCmdlineDescriptor
|
||||
|
||||
try:
|
||||
with unittest.mock.patch('avbtool.AvbKernelCmdlineDescriptor',
|
||||
SmuggledViaKernelCmdlineDescriptor):
|
||||
yield
|
||||
finally:
|
||||
avbtool.AvbKernelCmdlineDescriptor = orig_kernel
|
||||
|
||||
|
||||
def _get_descriptor_overrides(avb, paths):
|
||||
|
||||
Reference in New Issue
Block a user