Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-71339: Use new assertion methods in tests#129046

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
12 commits
Select commitHold shift + click to select a range
df921a3
gh-71339: Use new assertion methods in tests
serhiy-storchakaJun 30, 2023
c54a4cf
Fix test_cmd_line.
serhiy-storchakaJan 20, 2025
b253501
Remove redundant msgs.
serhiy-storchakaJan 20, 2025
b341ef3
Move some changes out to other PRs.
serhiy-storchakaJan 20, 2025
ac23640
Fix test_cmd_line again.
serhiy-storchakaJan 20, 2025
e98e19e
Merge branch 'main' into use-extra-assertions
JelleZijlstraJan 20, 2025
008cd2b
Restore "With" in other names.
serhiy-storchakaJan 21, 2025
cc1f37a
Merge branch 'main' into use-extra-assertions
serhiy-storchakaJan 21, 2025
3c985b8
Merge branch 'main' into use-extra-assertions
serhiy-storchakaApr 14, 2025
b26b204
Merge branch 'main' into use-extra-assertions
serhiy-storchakaApr 15, 2025
039bf0b
Merge branch 'main' into use-extra-assertions
serhiy-storchakaMay 22, 2025
ef68038
Merge remote-tracking branch 'refs/remotes/origin/use-extra-assertion…
serhiy-storchakaMay 22, 2025
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
NextNext commit
gh-71339: Use new assertion methods in tests
  • Loading branch information
@serhiy-storchaka
serhiy-storchaka committedJan 20, 2025
commitdf921a3014306a1eadb01c1e12acbd8a15553a75
2 changes: 1 addition & 1 deletionLib/idlelib/idle_test/test_grep.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,7 +143,7 @@ def test_found(self):
self.assertIn(pat, lines[0])
self.assertIn('py: 1:', lines[1]) # line number 1
self.assertIn('2', lines[3]) # hits found 2
self.assertTrue(lines[4].startswith('(Hint:'))
self.assertStartsWith(lines[4],'(Hint:')


class Default_commandTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletionLib/idlelib/idle_test/test_redirector.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,7 +34,7 @@ def test_close(self):
redir.register('insert', Func)
redir.close()
self.assertEqual(redir._operations, {})
self.assertFalse(hasattr(self.text, 'widget'))
self.assertNotHasAttr(self.text, 'widget')


class WidgetRedirectorTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletionLib/test/_test_embed_structseq.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@ def check_structseq(self, obj_type):
# ob_refcnt
self.assertGreaterEqual(sys.getrefcount(obj_type),1)
# tp_base
self.assertTrue(issubclass(obj_type,tuple))
self.assertIsSubclass(obj_type,tuple)
# tp_bases
self.assertEqual(obj_type.__bases__, (tuple,))
# tp_dict
Expand Down
12 changes: 6 additions & 6 deletionsLib/test/datetimetester.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,7 @@ class NotEnough(tzinfo):
def __init__(self, offset, name):
self.__offset = offset
self.__name = name
self.assertTrue(issubclass(NotEnough, tzinfo))
self.assertIsSubclass(NotEnough, tzinfo)
ne = NotEnough(3, "NotByALongShot")
self.assertIsInstance(ne, tzinfo)

Expand DownExpand Up@@ -231,7 +231,7 @@ def test_pickling_subclass(self):
self.assertIs(type(derived), otype)
self.assertEqual(derived.utcoffset(None), offset)
self.assertEqual(derived.tzname(None), oname)
self.assertFalse(hasattr(derived, 'spam'))
self.assertNotHasAttr(derived, 'spam')

def test_issue23600(self):
DSTDIFF = DSTOFFSET = timedelta(hours=1)
Expand DownExpand Up@@ -797,7 +797,7 @@ def test_roundtrip(self):

# Verify td -> string -> td identity.
s = repr(td)
self.assertTrue(s.startswith('datetime.'))
self.assertStartsWith(s,'datetime.')
s = s[9:]
td2 = eval(s)
self.assertEqual(td, td2)
Expand DownExpand Up@@ -1215,7 +1215,7 @@ def test_roundtrip(self):
self.theclass.today()):
# Verify dt -> string -> date identity.
s = repr(dt)
self.assertTrue(s.startswith('datetime.'))
self.assertStartsWith(s,'datetime.')
s = s[9:]
dt2 = eval(s)
self.assertEqual(dt, dt2)
Expand DownExpand Up@@ -2172,7 +2172,7 @@ def test_roundtrip(self):
self.theclass.now()):
# Verify dt -> string -> datetime identity.
s = repr(dt)
self.assertTrue(s.startswith('datetime.'))
self.assertStartsWith(s,'datetime.')
s = s[9:]
dt2 = eval(s)
self.assertEqual(dt, dt2)
Expand DownExpand Up@@ -3567,7 +3567,7 @@ def test_roundtrip(self):

# Verify t -> string -> time identity.
s = repr(t)
self.assertTrue(s.startswith('datetime.'))
self.assertStartsWith(s,'datetime.')
s = s[9:]
t2 = eval(s)
self.assertEqual(t, t2)
Expand Down
4 changes: 2 additions & 2 deletionsLib/test/mapping_tests.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,8 +70,8 @@ def test_read(self):
if not d: self.fail("Full mapping must compare to True")
# keys(), items(), iterkeys() ...
def check_iterandlist(iter, lst, ref):
self.assertTrue(hasattr(iter, '__next__'))
self.assertTrue(hasattr(iter, '__iter__'))
self.assertHasAttr(iter, '__next__')
self.assertHasAttr(iter, '__iter__')
x = list(iter)
self.assertTrue(set(x)==set(lst)==set(ref))
check_iterandlist(iter(d.keys()), list(d.keys()),
Expand Down
4 changes: 2 additions & 2 deletionsLib/test/pickletester.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3059,7 +3059,7 @@ def test_proto(self):
pickled = self.dumps(None, proto)
if proto >= 2:
proto_header = pickle.PROTO + bytes([proto])
self.assertTrue(pickled.startswith(proto_header))
self.assertStartsWith(pickled,proto_header)
else:
self.assertEqual(count_opcode(pickle.PROTO, pickled), 0)

Expand DownExpand Up@@ -4998,7 +4998,7 @@ def test_default_dispatch_table(self):
p = self.pickler_class(f, 0)
with self.assertRaises(AttributeError):
p.dispatch_table
self.assertFalse(hasattr(p, 'dispatch_table'))
self.assertNotHasAttr(p, 'dispatch_table')

def test_class_dispatch_table(self):
# A dispatch_table attribute can be specified class-wide
Expand Down
3 changes: 1 addition & 2 deletionsLib/test/support/warnings_helper.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,8 +23,7 @@ def check_syntax_warning(testcase, statement, errtext='',
testcase.assertEqual(len(warns), 1, warns)

warn, = warns
testcase.assertTrue(issubclass(warn.category, SyntaxWarning),
warn.category)
testcase.assertIsSubclass(warn.category, SyntaxWarning)
if errtext:
testcase.assertRegex(str(warn.message), errtext)
testcase.assertEqual(warn.filename, '<testcase>')
Expand Down
4 changes: 2 additions & 2 deletionsLib/test/test__osx_support.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,8 +65,8 @@ def test__find_build_tool(self):
'cc not found - check xcode-select')

def test__get_system_version(self):
self.assertTrue(platform.mac_ver()[0].startswith(
_osx_support._get_system_version()))
self.assertStartsWith(platform.mac_ver()[0],
_osx_support._get_system_version())

def test__remove_original_values(self):
config_vars = {
Expand Down
30 changes: 15 additions & 15 deletionsLib/test/test_abstract_numbers.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,11 +24,11 @@ def not_implemented(*args, **kwargs):

classTestNumbers(unittest.TestCase):
deftest_int(self):
self.assertTrue(issubclass(int,Integral))
self.assertTrue(issubclass(int,Rational))
self.assertTrue(issubclass(int,Real))
self.assertTrue(issubclass(int,Complex))
self.assertTrue(issubclass(int,Number))
self.assertIsSubclass(int,Integral)
self.assertIsSubclass(int,Rational)
self.assertIsSubclass(int,Real)
self.assertIsSubclass(int,Complex)
self.assertIsSubclass(int,Number)

self.assertEqual(7,int(7).real)
self.assertEqual(0,int(7).imag)
Expand All@@ -38,23 +38,23 @@ def test_int(self):
self.assertEqual(1,int(7).denominator)

deftest_float(self):
self.assertFalse(issubclass(float,Integral))
self.assertFalse(issubclass(float,Rational))
self.assertTrue(issubclass(float,Real))
self.assertTrue(issubclass(float,Complex))
self.assertTrue(issubclass(float,Number))
self.assertNotIsSubclass(float,Integral)
self.assertNotIsSubclass(float,Rational)
self.assertIsSubclass(float,Real)
self.assertIsSubclass(float,Complex)
self.assertIsSubclass(float,Number)

self.assertEqual(7.3,float(7.3).real)
self.assertEqual(0,float(7.3).imag)
self.assertEqual(7.3,float(7.3).conjugate())
self.assertEqual(-7.3,float(-7.3).conjugate())

deftest_complex(self):
self.assertFalse(issubclass(complex,Integral))
self.assertFalse(issubclass(complex,Rational))
self.assertFalse(issubclass(complex,Real))
self.assertTrue(issubclass(complex,Complex))
self.assertTrue(issubclass(complex,Number))
self.assertNotIsSubclass(complex,Integral)
self.assertNotIsSubclass(complex,Rational)
self.assertNotIsSubclass(complex,Real)
self.assertIsSubclass(complex,Complex)
self.assertIsSubclass(complex,Number)

c1,c2=complex(3,2),complex(4,1)
# XXX: This is not ideal, but see the comment in math_trunc().
Expand Down
4 changes: 2 additions & 2 deletionsLib/test/test_annotationlib.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -301,8 +301,8 @@ def test_special_attrs(self):
# __qualname__ make little sense for forward refs as they can store
# complex typing expressions.
fr = annotationlib.ForwardRef("set[Any]")
self.assertFalse(hasattr(fr, "__name__"))
self.assertFalse(hasattr(fr, "__qualname__"))
self.assertNotHasAttr(fr, "__name__")
self.assertNotHasAttr(fr, "__qualname__")
self.assertEqual(fr.__module__, "annotationlib")
# Forward refs are currently unpicklable once they contain a code object.
fr.__forward_code__ # fill the cache
Expand Down
2 changes: 1 addition & 1 deletionLib/test/test_argparse.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6755,7 +6755,7 @@ class TestImportStar(TestCase):

def test(self):
for name in argparse.__all__:
self.assertTrue(hasattr(argparse, name))
self.assertHasAttr(argparse, name)

def test_all_exports_everything_but_modules(self):
items = [
Expand Down
18 changes: 9 additions & 9 deletionsLib/test/test_ast/test_ast.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -253,12 +253,12 @@ def test_alias(self):
self.assertEqual(alias.end_col_offset, 17)

def test_base_classes(self):
self.assertTrue(issubclass(ast.For, ast.stmt))
self.assertTrue(issubclass(ast.Name, ast.expr))
self.assertTrue(issubclass(ast.stmt, ast.AST))
self.assertTrue(issubclass(ast.expr, ast.AST))
self.assertTrue(issubclass(ast.comprehension, ast.AST))
self.assertTrue(issubclass(ast.Gt, ast.AST))
self.assertIsSubclass(ast.For, ast.stmt)
self.assertIsSubclass(ast.Name, ast.expr)
self.assertIsSubclass(ast.stmt, ast.AST)
self.assertIsSubclass(ast.expr, ast.AST)
self.assertIsSubclass(ast.comprehension, ast.AST)
self.assertIsSubclass(ast.Gt, ast.AST)

def test_field_attr_existence(self):
for name, item in ast.__dict__.items():
Expand DownExpand Up@@ -909,7 +909,7 @@ def test_copy_with_parents(self):
def test_replace_interface(self):
for klass in self.iter_ast_classes():
with self.subTest(klass=klass):
self.assertTrue(hasattr(klass, '__replace__'))
self.assertHasAttr(klass, '__replace__')

fields = set(klass._fields)
with self.subTest(klass=klass, fields=fields):
Expand DownExpand Up@@ -1129,7 +1129,7 @@ def test_replace_reject_known_custom_instance_fields_commits(self):
context = node.ctx

# explicit rejection of known instance fields
self.assertTrue(hasattr(node, 'extra'))
self.assertHasAttr(node, 'extra')
msg = "Name.__replace__ got an unexpected keyword argument 'extra'."
with self.assertRaisesRegex(TypeError, re.escape(msg)):
copy.replace(node, extra=1)
Expand DownExpand Up@@ -2870,7 +2870,7 @@ def test_FunctionDef(self):
with self.assertWarnsRegex(DeprecationWarning,
r"FunctionDef\.__init__ missing 1 required positional argument: 'name'"):
node = ast.FunctionDef(args=args)
self.assertFalse(hasattr(node, "name"))
self.assertNotHasAttr(node, "name")
self.assertEqual(node.decorator_list, [])
node = ast.FunctionDef(name='foo', args=args)
self.assertEqual(node.name, 'foo')
Expand Down
2 changes: 1 addition & 1 deletionLib/test/test_asyncio/test_base_events.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1345,7 +1345,7 @@ def getaddrinfo_task(*args, **kwds):
with self.assertRaises(OSError) as cm:
self.loop.run_until_complete(coro)

self.assertTrue(str(cm.exception).startswith('Multiple exceptions: '))
self.assertStartsWith(str(cm.exception),'Multiple exceptions: ')
self.assertTrue(m_socket.socket.return_value.close.called)

coro = self.loop.create_connection(
Expand Down
5 changes: 2 additions & 3 deletionsLib/test/test_asyncio/test_events.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2184,7 +2184,7 @@ def test_subprocess_stderr(self):

transp.close()
self.assertEqual(b'OUT:test', proto.data[1])
self.assertTrue(proto.data[2].startswith(b'ERR:test'), proto.data[2])
self.assertStartsWith(proto.data[2],b'ERR:test')
self.assertEqual(0, proto.returncode)

@support.requires_subprocess()
Expand All@@ -2206,8 +2206,7 @@ def test_subprocess_stderr_redirect_to_stdout(self):

stdin.write(b'test')
self.loop.run_until_complete(proto.completed)
self.assertTrue(proto.data[1].startswith(b'OUT:testERR:test'),
proto.data[1])
self.assertStartsWith(proto.data[1], b'OUT:testERR:test')
self.assertEqual(b'', proto.data[2])

transp.close()
Expand Down
2 changes: 1 addition & 1 deletionLib/test/test_asyncio/test_futures.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -242,7 +242,7 @@ def test_uninitialized(self):

def test_future_cancel_message_getter(self):
f = self._new_future(loop=self.loop)
self.assertTrue(hasattr(f, '_cancel_message'))
self.assertHasAttr(f, '_cancel_message')
self.assertEqual(f._cancel_message, None)

f.cancel('my message')
Expand Down
12 changes: 6 additions & 6 deletionsLib/test/test_asyncio/test_locks.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,11 +27,11 @@ class LockTests(unittest.IsolatedAsyncioTestCase):

async def test_repr(self):
lock = asyncio.Lock()
self.assertTrue(repr(lock).endswith('[unlocked]>'))
self.assertEndsWith(repr(lock),'[unlocked]>')
self.assertTrue(RGX_REPR.match(repr(lock)))

await lock.acquire()
self.assertTrue(repr(lock).endswith('[locked]>'))
self.assertEndsWith(repr(lock),'[locked]>')
self.assertTrue(RGX_REPR.match(repr(lock)))

async def test_lock(self):
Expand DownExpand Up@@ -286,12 +286,12 @@ class EventTests(unittest.IsolatedAsyncioTestCase):

def test_repr(self):
ev = asyncio.Event()
self.assertTrue(repr(ev).endswith('[unset]>'))
self.assertEndsWith(repr(ev),'[unset]>')
match = RGX_REPR.match(repr(ev))
self.assertEqual(match.group('extras'), 'unset')

ev.set()
self.assertTrue(repr(ev).endswith('[set]>'))
self.assertEndsWith(repr(ev),'[set]>')
self.assertTrue(RGX_REPR.match(repr(ev)))

ev._waiters.append(mock.Mock())
Expand DownExpand Up@@ -916,11 +916,11 @@ def test_initial_value_zero(self):

async def test_repr(self):
sem = asyncio.Semaphore()
self.assertTrue(repr(sem).endswith('[unlocked, value:1]>'))
self.assertEndsWith(repr(sem),'[unlocked, value:1]>')
self.assertTrue(RGX_REPR.match(repr(sem)))

await sem.acquire()
self.assertTrue(repr(sem).endswith('[locked]>'))
self.assertEndsWith(repr(sem),'[locked]>')
self.assertTrue('waiters' not in repr(sem))
self.assertTrue(RGX_REPR.match(repr(sem)))

Expand Down
10 changes: 5 additions & 5 deletionsLib/test/test_asyncio/test_protocols.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@ def test_base_protocol(self):
self.assertIsNone(p.connection_lost(f))
self.assertIsNone(p.pause_writing())
self.assertIsNone(p.resume_writing())
self.assertFalse(hasattr(p, '__dict__'))
self.assertNotHasAttr(p, '__dict__')

def test_protocol(self):
f = mock.Mock()
Expand All@@ -30,7 +30,7 @@ def test_protocol(self):
self.assertIsNone(p.eof_received())
self.assertIsNone(p.pause_writing())
self.assertIsNone(p.resume_writing())
self.assertFalse(hasattr(p, '__dict__'))
self.assertNotHasAttr(p, '__dict__')

def test_buffered_protocol(self):
f = mock.Mock()
Expand All@@ -41,7 +41,7 @@ def test_buffered_protocol(self):
self.assertIsNone(p.buffer_updated(150))
self.assertIsNone(p.pause_writing())
self.assertIsNone(p.resume_writing())
self.assertFalse(hasattr(p, '__dict__'))
self.assertNotHasAttr(p, '__dict__')

def test_datagram_protocol(self):
f = mock.Mock()
Expand All@@ -50,7 +50,7 @@ def test_datagram_protocol(self):
self.assertIsNone(dp.connection_lost(f))
self.assertIsNone(dp.error_received(f))
self.assertIsNone(dp.datagram_received(f, f))
self.assertFalse(hasattr(dp, '__dict__'))
self.assertNotHasAttr(dp, '__dict__')

def test_subprocess_protocol(self):
f = mock.Mock()
Expand All@@ -60,7 +60,7 @@ def test_subprocess_protocol(self):
self.assertIsNone(sp.pipe_data_received(1, f))
self.assertIsNone(sp.pipe_connection_lost(1, f))
self.assertIsNone(sp.process_exited())
self.assertFalse(hasattr(sp, '__dict__'))
self.assertNotHasAttr(sp, '__dict__')


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletionLib/test/test_asyncio/test_queues.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@ async def _test_repr_or_str(self, fn, expect_id):
appear in fn(Queue()).
"""
q = asyncio.Queue()
self.assertTrue(fn(q).startswith('<Queue'), fn(q))
self.assertStartsWith(fn(q),'<Queue')
id_is_present = hex(id(q)) in fn(q)
self.assertEqual(expect_id, id_is_present)

Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp