bpo-5680: IDLE: Customize running a module (GH-13763) · python/cpython@ae526ee (original) (raw)

1

``

`-

"""Test query, coverage 91%).

`

``

1

`+

"""Test query, coverage 93%).

`

2

2

``

3

3

`Non-gui tests for Query, SectionName, ModuleName, and HelpSource use

`

4

4

`dummy versions that extract the non-gui methods and add other needed

`

`@@ -30,11 +30,9 @@ class Dummy_Query:

`

30

30

`ok = query.Query.ok

`

31

31

`cancel = query.Query.cancel

`

32

32

`# Add attributes and initialization needed for tests.

`

33

``

`-

entry = Var()

`

34

``

`-

entry_error = {}

`

35

33

`def init(self, dummy_entry):

`

36

``

`-

self.entry.set(dummy_entry)

`

37

``

`-

self.entry_error['text'] = ''

`

``

34

`+

self.entry = Var(value=dummy_entry)

`

``

35

`+

self.entry_error = {'text': ''}

`

38

36

`self.result = None

`

39

37

`self.destroyed = False

`

40

38

`def showerror(self, message):

`

`@@ -80,11 +78,9 @@ class SectionNameTest(unittest.TestCase):

`

80

78

`class Dummy_SectionName:

`

81

79

`entry_ok = query.SectionName.entry_ok # Function being tested.

`

82

80

`used_names = ['used']

`

83

``

`-

entry = Var()

`

84

``

`-

entry_error = {}

`

85

81

`def init(self, dummy_entry):

`

86

``

`-

self.entry.set(dummy_entry)

`

87

``

`-

self.entry_error['text'] = ''

`

``

82

`+

self.entry = Var(value=dummy_entry)

`

``

83

`+

self.entry_error = {'text': ''}

`

88

84

`def showerror(self, message):

`

89

85

`self.entry_error['text'] = message

`

90

86

``

`@@ -115,11 +111,9 @@ class ModuleNameTest(unittest.TestCase):

`

115

111

`class Dummy_ModuleName:

`

116

112

`entry_ok = query.ModuleName.entry_ok # Function being tested.

`

117

113

`text0 = ''

`

118

``

`-

entry = Var()

`

119

``

`-

entry_error = {}

`

120

114

`def init(self, dummy_entry):

`

121

``

`-

self.entry.set(dummy_entry)

`

122

``

`-

self.entry_error['text'] = ''

`

``

115

`+

self.entry = Var(value=dummy_entry)

`

``

116

`+

self.entry_error = {'text': ''}

`

123

117

`def showerror(self, message):

`

124

118

`self.entry_error['text'] = message

`

125

119

``

`@@ -144,9 +138,7 @@ def test_good_module_name(self):

`

144

138

`self.assertEqual(dialog.entry_error['text'], '')

`

145

139

``

146

140

``

147

``

`-

3 HelpSource test classes each test one function.

`

148

``

-

149

``

`-

orig_platform = query.platform

`

``

141

`+

3 HelpSource test classes each test one method.

`

150

142

``

151

143

`class HelpsourceBrowsefileTest(unittest.TestCase):

`

152

144

`"Test browse_file method of ModuleName subclass of Query."

`

`@@ -178,17 +170,16 @@ class HelpsourcePathokTest(unittest.TestCase):

`

178

170

``

179

171

`class Dummy_HelpSource:

`

180

172

`path_ok = query.HelpSource.path_ok

`

181

``

`-

path = Var()

`

182

``

`-

path_error = {}

`

183

173

`def init(self, dummy_path):

`

184

``

`-

self.path.set(dummy_path)

`

185

``

`-

self.path_error['text'] = ''

`

``

174

`+

self.path = Var(value=dummy_path)

`

``

175

`+

self.path_error = {'text': ''}

`

186

176

`def showerror(self, message, widget=None):

`

187

177

`self.path_error['text'] = message

`

188

178

``

``

179

`+

orig_platform = query.platform # Set in test_path_ok_file.

`

189

180

`@classmethod

`

190

181

`def tearDownClass(cls):

`

191

``

`-

query.platform = orig_platform

`

``

182

`+

query.platform = cls.orig_platform

`

192

183

``

193

184

`def test_path_ok_blank(self):

`

194

185

`dialog = self.Dummy_HelpSource(' ')

`

`@@ -242,6 +233,56 @@ def test_entry_ok_helpsource(self):

`

242

233

`self.assertEqual(dialog.entry_ok(), result)

`

243

234

``

244

235

``

``

236

`+

2 CustomRun test classes each test one method.

`

``

237

+

``

238

`+

class CustomRunCLIargsokTest(unittest.TestCase):

`

``

239

`+

"Test cli_ok method of the CustomRun subclass of Query."

`

``

240

+

``

241

`+

class Dummy_CustomRun:

`

``

242

`+

cli_args_ok = query.CustomRun.cli_args_ok

`

``

243

`+

def init(self, dummy_entry):

`

``

244

`+

self.entry = Var(value=dummy_entry)

`

``

245

`+

self.entry_error = {'text': ''}

`

``

246

`+

def showerror(self, message):

`

``

247

`+

self.entry_error['text'] = message

`

``

248

+

``

249

`+

def test_blank_args(self):

`

``

250

`+

dialog = self.Dummy_CustomRun(' ')

`

``

251

`+

self.assertEqual(dialog.cli_args_ok(), [])

`

``

252

+

``

253

`+

def test_invalid_args(self):

`

``

254

`+

dialog = self.Dummy_CustomRun("'no-closing-quote")

`

``

255

`+

self.assertEqual(dialog.cli_args_ok(), None)

`

``

256

`+

self.assertIn('No closing', dialog.entry_error['text'])

`

``

257

+

``

258

`+

def test_good_args(self):

`

``

259

`+

args = ['-n', '10', '--verbose', '-p', '/path', '--name']

`

``

260

`+

dialog = self.Dummy_CustomRun(' '.join(args) + ' "my name"')

`

``

261

`+

self.assertEqual(dialog.cli_args_ok(), args + ["my name"])

`

``

262

`+

self.assertEqual(dialog.entry_error['text'], '')

`

``

263

+

``

264

+

``

265

`+

class CustomRunEntryokTest(unittest.TestCase):

`

``

266

`+

"Test entry_ok method of the CustomRun subclass of Query."

`

``

267

+

``

268

`+

class Dummy_CustomRun:

`

``

269

`+

entry_ok = query.CustomRun.entry_ok

`

``

270

`+

entry_error = {}

`

``

271

`+

restartvar = Var()

`

``

272

`+

def cli_args_ok(self):

`

``

273

`+

return self.cli_args

`

``

274

+

``

275

`+

def test_entry_ok_customrun(self):

`

``

276

`+

dialog = self.Dummy_CustomRun()

`

``

277

`+

for restart in {True, False}:

`

``

278

`+

dialog.restartvar.set(restart)

`

``

279

`+

for cli_args, result in ((None, None),

`

``

280

`+

(['my arg'], (['my arg'], restart))):

`

``

281

`+

with self.subTest(restart=restart, cli_args=cli_args):

`

``

282

`+

dialog.cli_args = cli_args

`

``

283

`+

self.assertEqual(dialog.entry_ok(), result)

`

``

284

+

``

285

+

245

286

`# GUI TESTS

`

246

287

``

247

288

`class QueryGuiTest(unittest.TestCase):

`

`@@ -302,9 +343,7 @@ def test_click_section_name(self):

`

302

343

`dialog.entry.insert(0, 'okay')

`

303

344

`dialog.button_ok.invoke()

`

304

345

`self.assertEqual(dialog.result, 'okay')

`

305

``

`-

del dialog

`

306

346

`root.destroy()

`

307

``

`-

del root

`

308

347

``

309

348

``

310

349

`class ModulenameGuiTest(unittest.TestCase):

`

`@@ -321,9 +360,7 @@ def test_click_module_name(self):

`

321

360

`self.assertEqual(dialog.entry.get(), 'idlelib')

`

322

361

`dialog.button_ok.invoke()

`

323

362

`self.assertTrue(dialog.result.endswith('init.py'))

`

324

``

`-

del dialog

`

325

363

`root.destroy()

`

326

``

`-

del root

`

327

364

``

328

365

``

329

366

`class HelpsourceGuiTest(unittest.TestCase):

`

`@@ -343,9 +380,23 @@ def test_click_help_source(self):

`

343

380

`dialog.button_ok.invoke()

`

344

381

`prefix = "file://" if sys.platform == 'darwin' else ''

`

345

382

`Equal(dialog.result, ('test', prefix + file))

`

346

``

`-

del dialog

`

347

383

`root.destroy()

`

348

``

`-

del root

`

``

384

+

``

385

+

``

386

`+

class CustomRunGuiTest(unittest.TestCase):

`

``

387

+

``

388

`+

@classmethod

`

``

389

`+

def setUpClass(cls):

`

``

390

`+

requires('gui')

`

``

391

+

``

392

`+

def test_click_args(self):

`

``

393

`+

root = Tk()

`

``

394

`+

root.withdraw()

`

``

395

`+

dialog = query.CustomRun(root, 'Title', _utest=True)

`

``

396

`+

dialog.entry.insert(0, 'okay')

`

``

397

`+

dialog.button_ok.invoke()

`

``

398

`+

self.assertEqual(dialog.result, (['okay'], True))

`

``

399

`+

root.destroy()

`

349

400

``

350

401

``

351

402

`if name == 'main':

`