MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / test_sample

Method test_sample

tests/test_cli.py:331–384  ·  view source on GitHub ↗
(self, config_file_option)

Source from the content-addressed store, hash-verified

329 ("-f", ),
330 ])
331 def test_sample(self, config_file_option):
332 config_file = 'dwave.conf'
333 profile = 'profile'
334 client = 'qpu'
335 solver = '{"qpu": true}'
336 biases = '{1: 0}'
337 couplings = '{(1, 2): 1}'
338 num_reads = '10'
339 label = 'label'
340
341 with mock.patch('dwave.cloud.cli.Client') as m:
342 # mock returned solver
343 s = solver_object("qpu")
344 with mock.patch.object(s, "sample_ising") as sample_ising:
345 c = m.from_config.return_value
346 c.get_solver.return_value = s
347
348 runner = CliRunner()
349 with runner.isolated_filesystem():
350 touch(config_file)
351 result = runner.invoke(cli, ['sample',
352 config_file_option, config_file,
353 '--profile', profile,
354 '--client', client,
355 '--solver', solver,
356 '--label', label,
357 '-h', biases,
358 '-j', couplings,
359 '-n', num_reads])
360
361 # proper arguments passed to Client.from_config?
362 expected_config = dict(
363 config_file=config_file, profile=profile,
364 endpoint=None, region=None,
365 client=client, solver=solver)
366 call = m.from_config.call_args.kwargs
367 self.assertEqual(call, expected_config)
368
369 m.from_config.assert_called_with(
370 config_file=config_file, profile=profile,
371 endpoint=None, region=None,
372 client=client, solver=solver)
373
374 # get solver called?
375 c.get_solver.assert_called_with()
376
377 # sampling method called on solver?
378 sample_ising.assert_called_with(
379 {1: 0}, {(1, 2): 1}, 0.0, num_reads=10, label=label)
380
381 # verify output contains timing data
382 self.assertIn('Wall clock time', result.output)
383
384 self.assertEqual(result.exit_code, 0)
385
386 @parameterized.expand([
387 ("--config-file", ),

Callers

nothing calls this directly

Calls 2

solver_objectFunction · 0.90
touchFunction · 0.85

Tested by

no test coverage detected