本文整理汇总了Python中testtools.matchers.Not方法的典型用法代码示例。如果您正苦于以下问题:Python matchers.Not方法的具体用法?Python matchers.Not怎么用?Python matchers.Not使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testtools.matchers
的用法示例。
在下文中一共展示了matchers.Not方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_make_tmpfs_mount
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_make_tmpfs_mount(self):
"""
make_tmpfs_mount should create a tmpfs mountpoint that can be written
to. Once the mount is unmounted all files should be gone.
"""
mountpoint = self._get_directory_for_mount()
test_file = mountpoint.child(unicode(uuid4()))
self.manager_under_test.make_tmpfs_mount(mountpoint)
self.expectThat(test_file.path, Not(FileExists()))
test_file.touch()
self.expectThat(test_file.path, FileExists(),
'File did not exist after being touched on tmpfs.')
self.manager_under_test.unmount(mountpoint)
self.expectThat(test_file.path, Not(FileExists()),
'File persisted after tmpfs mount unmounted')
示例2: test_failed_run_deletes_snapshot
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_failed_run_deletes_snapshot(self):
# Patch out things that we don't want running during the test. Patch
# at a low level, so that we exercise all the function calls that a
# unit test might not put to the test.
self.patch_maaslog()
self.patch(boot_resources, "call_and_check")
self.patch(boot_resources, "service_monitor")
args = self.make_working_args()
# Cause the import to fail.
exception_type = factory.make_exception_type()
mock_download = self.patch(
boot_resources, "download_all_boot_resources"
)
mock_download.side_effect = exception_type()
# Run the import code.
self.assertRaises(exception_type, boot_resources.main, args)
# Verify the reuslts.
self.assertThat(os.path.join(self.storage, "cache"), Not(DirExists()))
self.assertThat(
os.path.join(self.storage, "current"), Not(DirExists())
)
示例3: test_attempts_to_assume_sole_responsibility_on_each_iteration
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_attempts_to_assume_sole_responsibility_on_each_iteration(self):
# A filesystem lock is used to prevent multiple network monitors from
# running on each host machine.
lock = NetworksMonitoringLock()
with lock:
service = self.makeService()
# Iterate one time.
yield service.updateInterfaces()
# Interfaces have not been recorded yet.
self.assertThat(service.interfaces, Equals([]))
# Iterate once more and ...
yield service.updateInterfaces()
# ... interfaces ARE recorded.
self.assertThat(service.interfaces, Not(Equals([])))
示例4: test_starts_and_stops_process
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_starts_and_stops_process(self):
service = SleepProcessProtocolService()
with TwistedLoggerFixture() as logger:
service.startService()
self.assertThat(service._protocol.done, Not(IsFiredDeferred()))
yield service.stopService()
result = yield service._protocol.done
self.assertThat(result, Is(None))
self.assertThat(
logger.output,
DocTestMatches(
"SleepProcessProtocolService started.\n"
"-...-\n"
"SleepProcessProtocolService ..."
),
)
with ExpectedException(ProcessExitedAlready):
service._process.signalProcess("INT")
示例5: test_restarts_process_after_finishing
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_restarts_process_after_finishing(self):
ifname = factory.make_name("eth")
service = NeighbourDiscoveryService(ifname, Mock())
mock_process_params = self.patch(service, "getProcessParameters")
mock_process_params.return_value = [b"/bin/echo", b"{}"]
service.clock = Clock()
service.startService()
# Wait for the protocol to finish
service.clock.advance(0.0)
yield service._protocol.done
# Advance the clock (should start the service again)
interval = service.step
service.clock.advance(interval)
# The Deferred should have been recreated.
self.assertThat(service._protocol.done, Not(IsFiredDeferred()))
yield service._protocol.done
service.stopService()
示例6: test_send_multicast_beacon_sets_ipv4_source
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_send_multicast_beacon_sets_ipv4_source(self):
# Note: Always use a random port for testing. (port=0)
protocol = BeaconingSocketProtocol(
reactor,
port=0,
process_incoming=True,
loopback=True,
interface="::",
debug=False,
)
self.assertThat(protocol.listen_port, Not(Is(None)))
listen_port = protocol.listen_port._realPortNumber
self.write_secret()
beacon = create_beacon_payload("advertisement", {})
protocol.send_multicast_beacon("127.0.0.1", beacon, port=listen_port)
# Verify that we received the packet.
yield wait_for_rx_packets(protocol, 1)
yield protocol.stopProtocol()
示例7: test_no_write_local
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_no_write_local(self):
config.write_config(False)
matcher_one = Not(
Contains(':fromhost-ip, !isequal, "127.0.0.1" ?MAASenlist')
)
matcher_two = Not(
Contains(':fromhost-ip, !isequal, "127.0.0.1" ?MAASboot')
)
# maas.log is still local when no write local.
matcher_three = Contains(':syslogtag, contains, "maas"')
self.assertThat(
"%s/%s" % (self.tmpdir, config.MAAS_SYSLOG_CONF_NAME),
FileContains(
matcher=MatchesAll(matcher_one, matcher_two, matcher_three)
),
)
示例8: test_creates_scripts
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_creates_scripts(self):
load_builtin_scripts()
for script in BUILTIN_SCRIPTS:
script_in_db = Script.objects.get(name=script.name)
# While MAAS allows user scripts to leave these fields blank,
# builtin scripts should always have values.
self.assertTrue(script_in_db.title, script.name)
self.assertTrue(script_in_db.description, script.name)
self.assertTrue(script_in_db.script.data, script.name)
self.assertThat(script_in_db.tags, Not(Equals([])), script.name)
# These values should always be set by the script loader.
self.assertEquals(
"Created by maas-%s" % get_maas_version(),
script_in_db.script.comment,
script.name,
)
self.assertTrue(script_in_db.default, script.name)
示例9: test_skips_dns_record_for_hostname_from_existing_node
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_skips_dns_record_for_hostname_from_existing_node(self):
subnet = factory.make_ipv4_Subnet_with_IPRanges(
with_static_range=False, dhcp_on=True
)
dynamic_range = subnet.get_dynamic_ranges()[0]
ip = factory.pick_ip_in_IPRange(dynamic_range)
hostname = factory.make_name().lower()
factory.make_Node(hostname=hostname)
kwargs = self.make_kwargs(action="commit", ip=ip, hostname=hostname)
update_lease(**kwargs)
unknown_interface = UnknownInterface.objects.filter(
mac_address=kwargs["mac"]
).first()
self.assertIsNotNone(unknown_interface)
self.assertEquals(subnet.vlan, unknown_interface.vlan)
sip = unknown_interface.ip_addresses.first()
self.assertIsNotNone(sip)
self.assertThat(sip.dnsresource_set.all(), Not(Contains(sip)))
示例10: test_skips_dns_record_for_coerced_hostname_from_existing_node
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_skips_dns_record_for_coerced_hostname_from_existing_node(self):
subnet = factory.make_ipv4_Subnet_with_IPRanges(
with_static_range=False, dhcp_on=True
)
dynamic_range = subnet.get_dynamic_ranges()[0]
ip = factory.pick_ip_in_IPRange(dynamic_range)
hostname = "gaming device"
factory.make_Node(hostname="gaming-device")
kwargs = self.make_kwargs(action="commit", ip=ip, hostname=hostname)
update_lease(**kwargs)
unknown_interface = UnknownInterface.objects.filter(
mac_address=kwargs["mac"]
).first()
self.assertIsNotNone(unknown_interface)
self.assertEquals(subnet.vlan, unknown_interface.vlan)
sip = unknown_interface.ip_addresses.first()
self.assertIsNotNone(sip)
self.assertThat(sip.dnsresource_set.all(), Not(Contains(sip)))
示例11: test_update_with_empty_space_clears_space
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_update_with_empty_space_clears_space(self):
self.become_admin()
fabric = factory.make_Fabric()
vlan = factory.make_VLAN(fabric=fabric, space=RANDOM)
self.assertThat(vlan.space, Not(Is(None)))
uri = get_vlan_uri(vlan, fabric)
response = self.client.put(uri, {"space": ""})
self.assertEqual(
http.client.OK, response.status_code, response.content
)
parsed_vlan = json.loads(
response.content.decode(settings.DEFAULT_CHARSET)
)
vlan = reload_object(vlan)
self.assertThat(vlan.space, Is(None))
self.assertThat(parsed_vlan["space"], Equals(Space.UNDEFINED))
示例12: test_update_with_undefined_space_clears_space
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_update_with_undefined_space_clears_space(self):
self.become_admin()
fabric = factory.make_Fabric()
vlan = factory.make_VLAN(fabric=fabric, space=RANDOM)
self.assertThat(vlan.space, Not(Is(None)))
uri = get_vlan_uri(vlan, fabric)
response = self.client.put(uri, {"space": Space.UNDEFINED})
self.assertEqual(
http.client.OK, response.status_code, response.content
)
parsed_vlan = json.loads(
response.content.decode(settings.DEFAULT_CHARSET)
)
vlan = reload_object(vlan)
self.assertThat(vlan.space, Is(None))
self.assertThat(parsed_vlan["space"], Equals(Space.UNDEFINED))
示例13: test_template_renders_with_no_warnings
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_template_renders_with_no_warnings(self):
"""The Tempita tmpl-api.rst template should render for the sample
annotated API docstring with no errors.
"""
ds = self.sample_api_annotated_docstring
template = APITemplateRenderer()
template_path = "%s/../%s" % (
os.path.dirname(__file__),
self.api_tempita_template,
)
api_docstring_parser = APIDocstringParser()
api_docstring_parser.parse(ds, uri=self.test_uri_plural)
result = template.apply_template(template_path, api_docstring_parser)
self.assertThat(result, Not(Contains("API_WARNING")))
示例14: test_POST_allocate_allocates_machine_by_storage
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_POST_allocate_allocates_machine_by_storage(self):
"""Storage label is returned alongside machine data"""
machine = factory.make_Node(
status=NODE_STATUS.READY, with_boot_disk=False
)
factory.make_PhysicalBlockDevice(
node=machine,
size=11 * (1000 ** 3),
tags=["ssd"],
formatted_root=True,
)
response = self.client.post(
reverse("machines_handler"),
{"op": "allocate", "storage": "needed:10(ssd)"},
)
self.assertThat(response, HasStatusCode(http.client.OK))
response_json = json.loads(
response.content.decode(settings.DEFAULT_CHARSET)
)
device_id = response_json["physicalblockdevice_set"][0]["id"]
constraints = response_json["constraints_by_type"]
self.expectThat(constraints, Contains("storage"))
self.expectThat(constraints["storage"], Contains("needed"))
self.expectThat(constraints["storage"]["needed"], Contains(device_id))
self.expectThat(constraints, Not(Contains("verbose_storage")))
示例15: test_handle_uncaught_exception_does_not_note_other_failure
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Not [as 别名]
def test_handle_uncaught_exception_does_not_note_other_failure(self):
handler = views.WebApplicationHandler()
request = make_request()
request.path = factory.make_name("path")
failure_type = factory.make_exception_type()
failure = failure_type, failure_type(), None
response = handler.handle_uncaught_exception(
request=request,
resolver=get_resolver(None),
exc_info=failure,
reraise=False,
)
# HTTP 500 is returned...
self.expectThat(
response.status_code, Equals(http.client.INTERNAL_SERVER_ERROR)
)
# ... but the response is NOT recorded as needing a retry.
self.expectThat(
handler._WebApplicationHandler__retry, Not(Contains(response))
)