Python testtools.content.text_content() Examples
The following are 30
code examples of testtools.content.text_content().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
testtools.content
, or try the search function
.
Example #1
Source File: test_hooks.py From keras-lambda with MIT License | 6 votes |
def test_command_hooks(self): """Test command hooks. Simple test that the appropriate command hooks run at the beginning/end of the appropriate command. """ stdout, _, return_code = self.run_setup('egg_info') assert 'build_ext pre-hook' not in stdout assert 'build_ext post-hook' not in stdout assert return_code == 0 stdout, stderr, return_code = self.run_setup('build_ext') self.addDetailUniqueName('stderr', text_content(stderr)) assert textwrap.dedent(""" running build_ext running pre_hook pbr_testpackage._setup_hooks.test_pre_hook for command build_ext build_ext pre-hook """) in stdout # flake8: noqa self.expectThat(stdout, EndsWith('build_ext post-hook')) assert return_code == 0
Example #2
Source File: test_scanner.py From reno with Apache License 2.0 | 6 votes |
def test_files_current_branch(self): self.repo.git('checkout', '2.0.0') self.repo.git('checkout', '-b', 'stable/2') f21 = self._add_notes_file('slug21') log_text = self.repo.git('log', '--decorate') self.addDetail('git log', text_content(log_text)) self.scanner = scanner.Scanner(self.c) raw_results = self.scanner.get_notes_by_version() results = { k: [f for (f, n) in v] for (k, v) in raw_results.items() } self.assertEqual( { '2.0.0-1': [f21], '2.0.0': [self.f2], }, results, )
Example #3
Source File: test_scanner.py From reno with Apache License 2.0 | 6 votes |
def test_modified_tagged_not_staged(self): # Prove that we can get a file we have changed but not staged. # Start with a standard commit and tag self._make_python_package() f1 = self._add_notes_file('slug1') self.repo.git('tag', '-s', '-m', 'first tag', '1.0.0') # Now modify the note fullpath = os.path.join(self.repo.reporoot, f1) with open(fullpath, 'w') as f: f.write('modified first note') status_results = self.repo.git('status') self.addDetail('git status', text_content(status_results)) # Now run the scanner self.scanner = scanner.Scanner(self.c) raw_results = self.scanner.get_notes_by_version() # Take the staged version of the file, but associate it with # tagged version 1.0.0 because the file was added before that # version. self.assertEqual( {'1.0.0': [(f1, None)], }, raw_results, )
Example #4
Source File: test_scanner.py From reno with Apache License 2.0 | 6 votes |
def test_added_tagged_not_staged(self): # Prove that we can get a file we have created but not staged. # Start with a standard commit and tag self._make_python_package() self.repo.git('tag', '-s', '-m', 'first tag', '1.0.0') # Now create a note without staging it n = self.get_note_num() basename = 'staged-note-%016x.yaml' % n filename = os.path.join(self.reporoot, 'releasenotes', 'notes', basename) create._make_note_file(filename, 'staged note') status_results = self.repo.git('status') self.addDetail('git status', text_content(status_results)) # Now run the scanner self.scanner = scanner.Scanner(self.c) raw_results = self.scanner.get_notes_by_version() # Take the staged version of the file, but associate it with # tagged version 1.0.0 because the file was added before that # version. self.assertEqual( {'1.0.0': [(os.path.join('releasenotes', 'notes', basename), None)], }, raw_results, )
Example #5
Source File: test_logger.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_twistd_low_verbosity(self): verbosity, set_verbosity = self._get_log_levels(1) name = factory.make_name("log.name") logged = log_something( name, verbosity=verbosity, set_verbosity=set_verbosity, mode=LoggingMode.TWISTD, ) self.addDetail("logged", text_content(logged)) observed = find_log_lines(logged) expected = [ (name, "warn", "From `twisted.logger`."), (name, "error", "From `twisted.logger`."), (name, "warn", "From `logging`."), (name, "error", "From `logging`."), ("maas." + name, "warn", "From `get_maas_logger`."), ("maas." + name, "error", "From `get_maas_logger`."), ("stderr", "error", "Printing to stderr."), ("-", "warn", "UserWarning: This is a warning!"), ] self.assertSequenceEqual(expected, observed)
Example #6
Source File: test_logger.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_twistd_lowest_verbosity(self): verbosity, set_verbosity = self._get_log_levels(0) name = factory.make_name("log.name") logged = log_something( name, verbosity=verbosity, set_verbosity=set_verbosity, mode=LoggingMode.TWISTD, ) self.addDetail("logged", text_content(logged)) observed = find_log_lines(logged) expected = [ (name, "error", "From `twisted.logger`."), (name, "error", "From `logging`."), ("maas." + name, "error", "From `get_maas_logger`."), ("stderr", "error", "Printing to stderr."), ] self.assertSequenceEqual(expected, observed)
Example #7
Source File: test_scanner.py From reno with Apache License 2.0 | 6 votes |
def test_staged_file(self): # Prove that we can get a file we have staged. # Start with a standard commit and tag self._make_python_package() self.repo.git('tag', '-s', '-m', 'first tag', '1.0.0') # Now stage a release note n = self.get_note_num() basename = 'staged-note-%016x.yaml' % n filename = os.path.join(self.reporoot, 'releasenotes', 'notes', basename) create._make_note_file(filename, 'staged note') self.repo.git('add', filename) status_results = self.repo.git('status') self.addDetail('git status', text_content(status_results)) # Now run the scanner self.scanner = scanner.Scanner(self.c) raw_results = self.scanner.get_notes_by_version() self.assertEqual( {'*working-copy*': [ (os.path.join('releasenotes', 'notes', basename), None)], }, raw_results, )
Example #8
Source File: test_volume.py From openstacksdk with Apache License 2.0 | 6 votes |
def test_volume_to_image(self): '''Test volume export to image functionality''' volume_name = self.getUniqueString() image_name = self.getUniqueString() self.addDetail('volume', content.text_content(volume_name)) self.addCleanup(self.cleanup, volume_name, image_name=image_name) volume = self.user_cloud.create_volume( display_name=volume_name, size=1) image = self.user_cloud.create_image( image_name, volume=volume, wait=True) volume_ids = [v['id'] for v in self.user_cloud.list_volumes()] self.assertIn(volume['id'], volume_ids) image_list = self.user_cloud.list_images() image_ids = [s['id'] for s in image_list] self.assertIn(image['id'], image_ids) self.user_cloud.delete_image(image_name, wait=True) self.user_cloud.delete_volume(volume_name, wait=True)
Example #9
Source File: test_hooks.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_command_hooks(self): """Test command hooks. Simple test that the appropriate command hooks run at the beginning/end of the appropriate command. """ stdout, _, return_code = self.run_setup('egg_info') assert 'build_ext pre-hook' not in stdout assert 'build_ext post-hook' not in stdout assert return_code == 0 stdout, stderr, return_code = self.run_setup('build_ext') self.addDetailUniqueName('stderr', text_content(stderr)) assert textwrap.dedent(""" running build_ext running pre_hook pbr_testpackage._setup_hooks.test_pre_hook for command build_ext build_ext pre-hook """) in stdout # flake8: noqa self.expectThat(stdout, EndsWith('build_ext post-hook')) assert return_code == 0
Example #10
Source File: test_volume.py From shade with Apache License 2.0 | 6 votes |
def test_volume_to_image(self): '''Test volume export to image functionality''' volume_name = self.getUniqueString() image_name = self.getUniqueString() self.addDetail('volume', content.text_content(volume_name)) self.addCleanup(self.cleanup, volume_name, image_name=image_name) volume = self.user_cloud.create_volume( display_name=volume_name, size=1) image = self.user_cloud.create_image( image_name, volume=volume, wait=True) volume_ids = [v['id'] for v in self.user_cloud.list_volumes()] self.assertIn(volume['id'], volume_ids) image_list = self.user_cloud.list_images() image_ids = [s['id'] for s in image_list] self.assertIn(image['id'], image_ids) self.user_cloud.delete_image(image_name, wait=True) self.user_cloud.delete_volume(volume_name, wait=True)
Example #11
Source File: test_floating_ip.py From shade with Apache License 2.0 | 5 votes |
def test_private_ip(self): self._setup_networks() new_server = self.user_cloud.get_openstack_vars( self.user_cloud.create_server( wait=True, name=self.new_item_name + '_server', image=self.image, flavor=self.flavor, nics=[self.nic])) self.addDetail( 'server', content.text_content(pprint.pformat(new_server))) self.assertNotEqual(new_server['private_v4'], '')
Example #12
Source File: test_scanner.py From reno with Apache License 2.0 | 5 votes |
def test_rename_then_delete_file(self): self._make_python_package() self.repo.git('tag', '-s', '-m', 'first tag', '1.0.0') f1 = self._add_notes_file('slug1') f2 = f1.replace('slug1', 'slug2') self.repo.git('mv', f1, f2) self.repo.git('status') self.repo.commit('rename note file') self.repo.git('rm', f2) self.repo.commit('remove note file') f3 = self._add_notes_file('slug3') self.repo.git('tag', '-s', '-m', 'first tag', '2.0.0') log_results = self.repo.git('log', '--topo-order', '--pretty=%H %d', '--name-only') self.addDetail('git log', text_content(log_results)) self.scanner = scanner.Scanner(self.c) raw_results = self.scanner.get_notes_by_version() results = { k: [f for (f, n) in v] for (k, v) in raw_results.items() } self.assertEqual( {'2.0.0': [f3], }, results, )
Example #13
Source File: test_floating_ip.py From shade with Apache License 2.0 | 5 votes |
def _setup_networks(self): if self.user_cloud.has_service('network'): # Create a network self.test_net = self.user_cloud.create_network( name=self.new_item_name + '_net') # Create a subnet on it self.test_subnet = self.user_cloud.create_subnet( subnet_name=self.new_item_name + '_subnet', network_name_or_id=self.test_net['id'], cidr='10.24.4.0/24', enable_dhcp=True ) # Create a router self.test_router = self.user_cloud.create_router( name=self.new_item_name + '_router') # Attach the router to an external network ext_nets = self.user_cloud.search_networks( filters={'router:external': True}) self.user_cloud.update_router( name_or_id=self.test_router['id'], ext_gateway_net_id=ext_nets[0]['id']) # Attach the router to the internal subnet self.user_cloud.add_router_interface( self.test_router, subnet_id=self.test_subnet['id']) # Select the network for creating new servers self.nic = {'net-id': self.test_net['id']} self.addDetail( 'networks-neutron', content.text_content(pprint.pformat( self.user_cloud.list_networks()))) else: # Find network names for nova-net data = self.user_cloud._compute_client.get('/os-tenant-networks') nets = meta.get_and_munchify('networks', data) self.addDetail( 'networks-nova', content.text_content(pprint.pformat( nets))) self.nic = {'net-id': nets[0].id}
Example #14
Source File: base.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def setUp(self): super(CapturedSubprocess, self).setUp() proc = subprocess.Popen(*self.args, **self.kwargs) out, err = proc.communicate() self.out = out.decode('utf-8', 'replace') self.err = err.decode('utf-8', 'replace') self.addDetail(self.label + '-stdout', content.text_content(self.out)) self.addDetail(self.label + '-stderr', content.text_content(self.err)) self.returncode = proc.returncode if proc.returncode: raise AssertionError('Failed process %s' % proc.returncode) self.addCleanup(delattr, self, 'out') self.addCleanup(delattr, self, 'err') self.addCleanup(delattr, self, 'returncode')
Example #15
Source File: test_volume.py From shade with Apache License 2.0 | 5 votes |
def test_volumes(self): '''Test volume and snapshot functionality''' volume_name = self.getUniqueString() snapshot_name = self.getUniqueString() self.addDetail('volume', content.text_content(volume_name)) self.addCleanup(self.cleanup, volume_name, snapshot_name=snapshot_name) volume = self.user_cloud.create_volume( display_name=volume_name, size=1) snapshot = self.user_cloud.create_volume_snapshot( volume['id'], display_name=snapshot_name ) ret_volume = self.user_cloud.get_volume_by_id(volume['id']) self.assertEqual(volume['id'], ret_volume['id']) volume_ids = [v['id'] for v in self.user_cloud.list_volumes()] self.assertIn(volume['id'], volume_ids) snapshot_list = self.user_cloud.list_volume_snapshots() snapshot_ids = [s['id'] for s in snapshot_list] self.assertIn(snapshot['id'], snapshot_ids) ret_snapshot = self.user_cloud.get_volume_snapshot_by_id( snapshot['id']) self.assertEqual(snapshot['id'], ret_snapshot['id']) self.user_cloud.delete_volume_snapshot(snapshot_name, wait=True) self.user_cloud.delete_volume(volume_name, wait=True)
Example #16
Source File: test_scanner.py From reno with Apache License 2.0 | 5 votes |
def test_files_stable_from_master_no_stop_base(self): self.repo.git('checkout', '2.0.0') self.repo.git('checkout', '-b', 'stable/2') f21 = self._add_notes_file('slug21') self.repo.git('checkout', 'master') log_text = self.repo.git('log', '--pretty=%x00%H %d', '--name-only', 'stable/2') self.addDetail('git log', text_content(log_text)) self.c.override( branch='stable/2', ) self.c.override( stop_at_branch_base=False, ) self.scanner = scanner.Scanner(self.c) raw_results = self.scanner.get_notes_by_version() results = { k: [f for (f, n) in v] for (k, v) in raw_results.items() } self.assertEqual( { '1.0.0': [self.f1], '2.0.0': [self.f2], '2.0.0-1': [f21], }, results, )
Example #17
Source File: test_scanner.py From reno with Apache License 2.0 | 5 votes |
def test_pre_release_branch_no_collapse(self): f4 = self._add_notes_file('slug4') self.repo.git('tag', '-s', '-m', 'pre-release', '4.0.0.0rc1') # Add a commit on master after the tag self._add_notes_file('slug5') # Move back to the tag and create the branch self.repo.git('checkout', '4.0.0.0rc1') self.repo.git('checkout', '-b', 'stable/4') # Create a commit on the branch f41 = self._add_notes_file('slug41') log_text = self.repo.git( 'log', '--pretty=%x00%H %d', '--name-only', '--graph', '--all', '--decorate', ) self.addDetail('git log', text_content(log_text)) rev_list = self.repo.git('rev-list', '--first-parent', '^stable/4', 'master') self.addDetail('rev-list', text_content(rev_list)) self.c.override( branch='stable/4', collapse_pre_releases=False, ) self.scanner = scanner.Scanner(self.c) raw_results = self.scanner.get_notes_by_version() results = { k: [f for (f, n) in v] for (k, v) in raw_results.items() } self.assertEqual( { '4.0.0.0rc1': [f4], '4.0.0.0rc1-1': [f41], }, results, )
Example #18
Source File: test_scanner.py From reno with Apache License 2.0 | 5 votes |
def test_pre_release_branch_collapse(self): f4 = self._add_notes_file('slug4') self.repo.git('tag', '-s', '-m', 'pre-release', '4.0.0.0rc1') # Add a commit on master after the tag self._add_notes_file('slug5') # Move back to the tag and create the branch self.repo.git('checkout', '4.0.0.0rc1') self.repo.git('checkout', '-b', 'stable/4') # Create a commit on the branch f41 = self._add_notes_file('slug41') self.repo.git('tag', '-s', '-m', 'release', '4.0.0') log_text = self.repo.git( 'log', '--pretty=%x00%H %d', '--name-only', '--graph', '--all', '--decorate', ) self.addDetail('git log', text_content(log_text)) rev_list = self.repo.git('rev-list', '--first-parent', '^stable/4', 'master') self.addDetail('rev-list', text_content(rev_list)) self.c.override( branch='stable/4', collapse_pre_releases=True, ) self.scanner = scanner.Scanner(self.c) raw_results = self.scanner.get_notes_by_version() results = { k: [f for (f, n) in v] for (k, v) in raw_results.items() } self.assertEqual( { '4.0.0': [f4, f41], }, results, )
Example #19
Source File: test_scanner.py From reno with Apache License 2.0 | 5 votes |
def test_pre_release_note_before_branch(self): f4 = self._add_notes_file('slug4') self.repo.git('tag', '-s', '-m', 'beta', '4.0.0.0b1') self.repo.add_file('not-a-release-note.txt') self.repo.git('tag', '-s', '-m', 'pre-release', '4.0.0.0rc1') # Add a commit on master after the tag self._add_notes_file('slug5') # Move back to the tag and create the branch self.repo.git('checkout', '4.0.0.0rc1') self.repo.git('checkout', '-b', 'stable/4') # Create a commit on the branch f41 = self._add_notes_file('slug41') self.repo.git('tag', '-s', '-m', 'release', '4.0.0') log_text = self.repo.git( 'log', '--pretty=%x00%H %d', '--name-only', '--graph', '--all', '--decorate', ) self.addDetail('git log', text_content(log_text)) rev_list = self.repo.git('rev-list', '--first-parent', '^stable/4', 'master') self.addDetail('rev-list', text_content(rev_list)) self.c.override( branch='stable/4', collapse_pre_releases=True, ) self.scanner = scanner.Scanner(self.c) raw_results = self.scanner.get_notes_by_version() results = { k: [f for (f, n) in v] for (k, v) in raw_results.items() } self.assertEqual( { '4.0.0': [f4, f41], }, results, )
Example #20
Source File: test_scanner.py From reno with Apache License 2.0 | 5 votes |
def test_full_release_branch(self): f4 = self._add_notes_file('slug4') self.repo.git('tag', '-s', '-m', 'release', '4.0.0') # Add a commit on master after the tag self._add_notes_file('slug5') # Move back to the tag and create the branch self.repo.git('checkout', '4.0.0') self.repo.git('checkout', '-b', 'stable/4') # Create a commit on the branch f41 = self._add_notes_file('slug41') log_text = self.repo.git( 'log', '--pretty=%x00%H %d', '--name-only', '--graph', '--all', '--decorate', ) self.addDetail('git log', text_content(log_text)) rev_list = self.repo.git('rev-list', '--first-parent', '^stable/4', 'master') self.addDetail('rev-list', text_content(rev_list)) self.c.override( branch='stable/4', ) self.scanner = scanner.Scanner(self.c) raw_results = self.scanner.get_notes_by_version() results = { k: [f for (f, n) in v] for (k, v) in raw_results.items() } self.assertEqual( { '4.0.0': [f4], '4.0.0-1': [f41], }, results, )
Example #21
Source File: test_scanner.py From reno with Apache License 2.0 | 5 votes |
def test_branch_no_more_commits(self): # We have branched from master, but not added any commits to # our branch or to master. f4 = self._add_notes_file('slug4') self.repo.git('tag', '-s', '-m', 'release', '4.0.0') self.repo.git('checkout', '-b', 'stable/4') # Create a commit on the branch log_text = self.repo.git( 'log', '--pretty=%x00%H %d', '--name-only', '--graph', '--all', '--decorate', ) self.addDetail('git log', text_content(log_text)) rev_list = self.repo.git('rev-list', '--first-parent', '^stable/4', 'master') self.addDetail('rev-list', text_content(rev_list)) self.c.override( branch='stable/4', ) self.scanner = scanner.Scanner(self.c) raw_results = self.scanner.get_notes_by_version() results = { k: [f for (f, n) in v] for (k, v) in raw_results.items() } self.assertEqual( { '4.0.0': [f4], }, results, )
Example #22
Source File: test_node_info_scripts.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def run_script(self, script): script_filename = self.make_file("test.py", script) os.chmod(script_filename, 0o700) try: return check_output((script_filename,), stderr=STDOUT) except CalledProcessError as error: self.addDetail( "output", text_content(error.output.decode("ascii", "replace")) ) raise
Example #23
Source File: test_logger.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_twistd_default_verbosity(self): verbosity, set_verbosity = self._get_log_levels(2) name = factory.make_name("log.name") logged = log_something( name, verbosity=verbosity, set_verbosity=set_verbosity, mode=LoggingMode.TWISTD, ) self.addDetail("logged", text_content(logged)) observed = find_log_lines(logged) expected = [ (name, "info", "From `twisted.logger`."), (name, "warn", "From `twisted.logger`."), (name, "error", "From `twisted.logger`."), (name, "info", "From `twisted.python.log`."), ("logsomething", "info", "From `twisted.python.log.logfile`."), (name, "info", "From `logging`."), (name, "warn", "From `logging`."), (name, "error", "From `logging`."), ("maas." + name, "info", "From `get_maas_logger`."), ("maas." + name, "warn", "From `get_maas_logger`."), ("maas." + name, "error", "From `get_maas_logger`."), ("stdout", "info", "Printing to stdout."), ("stderr", "error", "Printing to stderr."), ("-", "warn", "UserWarning: This is a warning!"), ] self.assertSequenceEqual(expected, observed)
Example #24
Source File: test_logger.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_twistd_high_verbosity(self): verbosity, set_verbosity = self._get_log_levels(3) name = factory.make_name("log.name") logged = log_something( name, verbosity=verbosity, set_verbosity=set_verbosity, mode=LoggingMode.TWISTD, ) self.addDetail("logged", text_content(logged)) observed = find_log_lines(logged) expected = [ (name, "debug", "From `twisted.logger`."), (name, "info", "From `twisted.logger`."), (name, "warn", "From `twisted.logger`."), (name, "error", "From `twisted.logger`."), (name, "info", "From `twisted.python.log`."), ("logsomething", "info", "From `twisted.python.log.logfile`."), (name, "debug", "From `logging`."), (name, "info", "From `logging`."), (name, "warn", "From `logging`."), (name, "error", "From `logging`."), ("maas." + name, "debug", "From `get_maas_logger`."), ("maas." + name, "info", "From `get_maas_logger`."), ("maas." + name, "warn", "From `get_maas_logger`."), ("maas." + name, "error", "From `get_maas_logger`."), ("stdout", "info", "Printing to stdout."), ("stderr", "error", "Printing to stderr."), ("-", "warn", "UserWarning: This is a warning!"), ] self.assertSequenceEqual(expected, observed)
Example #25
Source File: test_logger.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_command_high_verbosity(self): verbosity, set_verbosity = self._get_log_levels(3) name = factory.make_name("log.name") logged = log_something( name, verbosity=verbosity, set_verbosity=set_verbosity, mode=LoggingMode.COMMAND, ) self.addDetail("logged", text_content(logged)) observed = find_log_lines(logged) expected = [ (name, "debug", "From `twisted.logger`."), (name, "info", "From `twisted.logger`."), (name, "warn", "From `twisted.logger`."), (name, "error", "From `twisted.logger`."), (name, "info", "From `twisted.python.log`."), ("logsomething", "info", "From `twisted.python.log.logfile`."), (name, "debug", "From `logging`."), (name, "info", "From `logging`."), (name, "warn", "From `logging`."), (name, "error", "From `logging`."), ("maas." + name, "debug", "From `get_maas_logger`."), ("maas." + name, "info", "From `get_maas_logger`."), ("maas." + name, "warn", "From `get_maas_logger`."), ("maas." + name, "error", "From `get_maas_logger`."), ] self.assertSequenceEqual(expected, observed) self.assertThat( logged, DocTestMatches( """\ ... Printing to stdout. Printing to stderr. This is a warning! """ ), )
Example #26
Source File: test_logger.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_command_low_verbosity(self): verbosity, set_verbosity = self._get_log_levels(1) name = factory.make_name("log.name") logged = log_something( name, verbosity=verbosity, set_verbosity=set_verbosity, mode=LoggingMode.COMMAND, ) self.addDetail("logged", text_content(logged)) observed = find_log_lines(logged) expected = [ (name, "warn", "From `twisted.logger`."), (name, "error", "From `twisted.logger`."), (name, "warn", "From `logging`."), (name, "error", "From `logging`."), ("maas." + name, "warn", "From `get_maas_logger`."), ("maas." + name, "error", "From `get_maas_logger`."), ] self.assertSequenceEqual(expected, observed) self.assertThat( logged, DocTestMatches( """\ ... Printing to stdout. Printing to stderr. This is a warning! """ ), )
Example #27
Source File: test_logger.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_command_lowest_verbosity(self): verbosity, set_verbosity = self._get_log_levels(0) name = factory.make_name("log.name") logged = log_something( name, verbosity=verbosity, set_verbosity=set_verbosity, mode=LoggingMode.COMMAND, ) self.addDetail("logged", text_content(logged)) observed = find_log_lines(logged) expected = [ (name, "error", "From `twisted.logger`."), (name, "error", "From `logging`."), ("maas." + name, "error", "From `get_maas_logger`."), ] self.assertSequenceEqual(expected, observed) self.assertThat( logged, DocTestMatches( """\ ... Printing to stdout. Printing to stderr. This is a warning! """ ), )
Example #28
Source File: test_preseed_storage.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def assertStorageConfig(self, expected, observed, strip_uuids=False): self.assertThat(observed, IsInstance(list)) self.assertThat(observed, HasLength(1)) observed = observed[0] observed = yaml.safe_load(observed) self.assertThat( observed, ContainsDict( { "partitioning_commands": MatchesDict( {"builtin": Equals(["curtin", "block-meta", "custom"])} ), "storage": MatchesDict( {"version": Equals(1), "config": IsInstance(list)} ), } ), ) storage_observed = observed["storage"]["config"] storage_expected = yaml.safe_load(expected)["config"] if strip_uuids: storage_observed = self.stripUUIDs(storage_observed) storage_expected = self.stripUUIDs(storage_expected) if storage_observed != storage_expected: storage_observed_dump = yaml.safe_dump( storage_observed, default_flow_style=False ) storage_expected_dump = yaml.safe_dump( storage_expected, default_flow_style=False ) diff = ["--- expected", "+++ observed"] diff.extend( ndiff( storage_expected_dump.splitlines(), storage_observed_dump.splitlines(), ) ) self.addDetail("Differences", text_content("\n".join(diff))) self.fail("Storage configurations differ.")
Example #29
Source File: base.py From keras-lambda with MIT License | 5 votes |
def setUp(self): super(CapturedSubprocess, self).setUp() proc = subprocess.Popen(*self.args, **self.kwargs) out, err = proc.communicate() self.out = out.decode('utf-8', 'replace') self.err = err.decode('utf-8', 'replace') self.addDetail(self.label + '-stdout', content.text_content(self.out)) self.addDetail(self.label + '-stderr', content.text_content(self.err)) self.returncode = proc.returncode if proc.returncode: raise AssertionError('Failed process %s' % proc.returncode) self.addCleanup(delattr, self, 'out') self.addCleanup(delattr, self, 'err') self.addCleanup(delattr, self, 'returncode')
Example #30
Source File: test_commands.py From keras-lambda with MIT License | 5 votes |
def test_custom_build_py_command(self): """Test custom build_py command. Test that a custom subclass of the build_py command runs when listed in the commands [global] option, rather than the normal build command. """ stdout, stderr, return_code = self.run_setup('build_py') self.addDetail('stdout', content.text_content(stdout)) self.addDetail('stderr', content.text_content(stderr)) self.assertIn('Running custom build_py command.', stdout) self.assertEqual(return_code, 0)