Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Tests Python 3.11 Compatible #34506

Merged
merged 6 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lms/djangoapps/instructor/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def test_bad_file_upload_type(self):
"""
Try uploading some non-CSV file and verify that it is rejected
"""
uploaded_file = SimpleUploadedFile("temp.csv", io.BytesIO(b"some initial binary data: \x00\x01").read())
uploaded_file = SimpleUploadedFile("temp.csv", io.BytesIO(b"some initial binary data: \xC3\x01").read())
response = self.client.post(self.url, {'students_list': uploaded_file})
assert response.status_code == 200
data = json.loads(response.content.decode('utf-8'))
Expand Down Expand Up @@ -920,15 +920,16 @@ def test_users_created_and_enrolled_successfully_if_others_fail(self):
manual_enrollments = ManualEnrollmentAudit.objects.all()
assert manual_enrollments.count() == 2

@patch('lms.djangoapps.instructor.views.api', 'generate_random_string',
Mock(side_effect=['first', 'first', 'second']))
def test_generate_unique_password_no_reuse(self):
"""
generate_unique_password should generate a unique password string that hasn't been generated before.
"""
generated_password = ['first']
password = generate_unique_password(generated_password, 12)
assert password != 'first'
with patch('lms.djangoapps.instructor.views.api.generate_random_string') as mock:
mock.side_effect = ['first', 'first', 'second']

generated_password = ['first']
password = generate_unique_password(generated_password, 12)
assert password != 'first'

@patch.dict(settings.FEATURES, {'ALLOW_AUTOMATED_SIGNUPS': False})
def test_allow_automated_signups_flag_not_set(self):
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/instructor/tests/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ def test_bad_file_upload_type(self):
"""
Try uploading CSV file with invalid binary data and verify that it is rejected
"""
uploaded_file = SimpleUploadedFile("temp.csv", io.BytesIO(b"some initial binary data: \x00\x01").read())
uploaded_file = SimpleUploadedFile("temp.csv", io.BytesIO(b"some initial binary data: \xC3\x01").read())
response = self.client.post(self.url, {'students_list': uploaded_file})
assert response.status_code == 200
data = json.loads(response.content.decode('utf-8'))
Expand Down
7 changes: 5 additions & 2 deletions openedx/core/lib/cache_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __init__(self, func):
self.cache = {}

def __call__(self, *args):
if not isinstance(args, collections.Hashable):
if not isinstance(args, collections.abc.Hashable):
# uncacheable. a list, for instance.
# better to not cache than blow up.
return self.func(*args)
Expand All @@ -147,7 +147,10 @@ def __get__(self, obj, objtype):
"""
Support instance methods.
"""
return functools.partial(self.__call__, obj)
partial = functools.partial(self.__call__, obj)
# Make the cache accessible on the wrapped object so it can be cleared if needed.
partial.cache = self.cache
return partial


class CacheInvalidationManager:
Expand Down
4 changes: 2 additions & 2 deletions xmodule/library_content_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def make_selection(cls, selected, children, max_count, mode):
overlimit_block_keys = set()
if len(selected_keys) > max_count:
num_to_remove = len(selected_keys) - max_count
overlimit_block_keys = set(rand.sample(selected_keys, num_to_remove))
overlimit_block_keys = set(rand.sample(list(selected_keys), num_to_remove))
selected_keys -= overlimit_block_keys

# Do we have enough blocks now?
Expand All @@ -233,7 +233,7 @@ def make_selection(cls, selected, children, max_count, mode):
pool = valid_block_keys - selected_keys
if mode == "random":
num_to_add = min(len(pool), num_to_add)
added_block_keys = set(rand.sample(pool, num_to_add))
added_block_keys = set(rand.sample(list(pool), num_to_add))
# We now have the correct n random children to show for this user.
else:
raise NotImplementedError("Unsupported mode.")
Expand Down
2 changes: 1 addition & 1 deletion xmodule/tests/xml/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __repr__(self):

# Extract all argument names used to construct XmlImportData objects,
# so that the factory doesn't treat them as XML attributes
XML_IMPORT_ARGS = inspect.getargspec(XmlImportData.__init__).args # lint-amnesty, pylint: disable=deprecated-method
XML_IMPORT_ARGS = inspect.getfullargspec(XmlImportData.__init__).args


class XmlImportFactory(Factory):
Expand Down
Loading