@@ -722,12 +722,13 @@ def test_010_on_qdb_change_multiple_assignments_including_full(self):
722
722
qubesusbproxy .core3ext .USBDevice (Port (back , "1-1" , "usb" ))
723
723
)
724
724
725
- self .ext .attach_and_notify = AsyncMock ()
726
725
loop = asyncio .get_event_loop ()
727
- loop .run_until_complete (self .ext .on_domain_start (front , None ))
728
- self .assertEqual (
729
- self .ext .attach_and_notify .call_args [0 ][1 ].options , {"pid" : "did" }
730
- )
726
+ with (mock .patch .object (self .ext , "attach_and_notify" )
727
+ as attach_and_notify ):
728
+ loop .run_until_complete (self .ext .on_domain_start (front , None ))
729
+ self .assertEqual (
730
+ attach_and_notify .call_args [0 ][1 ].options , {"pid" : "did" }
731
+ )
731
732
732
733
def test_011_on_qdb_change_multiple_assignments_port_vs_dev (self ):
733
734
back , front = self .added_assign_setup ()
@@ -752,12 +753,13 @@ def test_011_on_qdb_change_multiple_assignments_port_vs_dev(self):
752
753
qubesusbproxy .core3ext .USBDevice (Port (back , "1-1" , "usb" ))
753
754
)
754
755
755
- self .ext .attach_and_notify = AsyncMock ()
756
756
loop = asyncio .get_event_loop ()
757
- loop .run_until_complete (self .ext .on_domain_start (front , None ))
758
- self .assertEqual (
759
- self .ext .attach_and_notify .call_args [0 ][1 ].options , {"pid" : "any" }
760
- )
757
+ with (mock .patch .object (self .ext , "attach_and_notify" )
758
+ as attach_and_notify ):
759
+ loop .run_until_complete (self .ext .on_domain_start (front , None ))
760
+ self .assertEqual (
761
+ attach_and_notify .call_args [0 ][1 ].options , {"pid" : "any" }
762
+ )
761
763
762
764
def test_012_on_qdb_change_multiple_assignments_dev (self ):
763
765
back , front = self .added_assign_setup ()
@@ -785,12 +787,13 @@ def test_012_on_qdb_change_multiple_assignments_dev(self):
785
787
qubesusbproxy .core3ext .USBDevice (Port (back , "1-2" , "usb" ))
786
788
)
787
789
788
- self .ext .attach_and_notify = AsyncMock ()
789
790
loop = asyncio .get_event_loop ()
790
- loop .run_until_complete (self .ext .on_domain_start (front , None ))
791
- self .assertEqual (
792
- self .ext .attach_and_notify .call_args [0 ][1 ].options , {"any" : "did" }
793
- )
791
+ with (mock .patch .object (self .ext , "attach_and_notify" )
792
+ as attach_and_notify ):
793
+ loop .run_until_complete (self .ext .on_domain_start (front , None ))
794
+ self .assertEqual (
795
+ attach_and_notify .call_args [0 ][1 ].options , {"any" : "did" }
796
+ )
794
797
795
798
def test_013_on_qdb_change_two_fronts (self ):
796
799
back , front = self .added_assign_setup ()
@@ -826,13 +829,14 @@ def test_014_failed_confirmation(self, socket):
826
829
socket .return_value = "allow:nonsense"
827
830
828
831
loop = asyncio .get_event_loop ()
829
- self .ext .attach_and_notify = AsyncMock ()
830
- loop .run_until_complete (
831
- qubes .ext .utils .resolve_conflicts_and_attach (
832
- self .ext , {"1-1" : {front : assmnt , back : assmnt }}
832
+ with (mock .patch .object (self .ext , "attach_and_notify" )
833
+ as attach_and_notify ):
834
+ loop .run_until_complete (
835
+ qubes .ext .utils .resolve_conflicts_and_attach (
836
+ self .ext , {"1-1" : {front : assmnt , back : assmnt }}
837
+ )
833
838
)
834
- )
835
- self .ext .attach_and_notify .assert_not_called ()
839
+ attach_and_notify .assert_not_called ()
836
840
837
841
# call_socket_service returns coroutine
838
842
@unittest .mock .patch (
@@ -850,13 +854,14 @@ def test_015_successful_confirmation(self, socket):
850
854
socket .return_value = "allow:front-vm"
851
855
852
856
loop = asyncio .get_event_loop ()
853
- self .ext .attach_and_notify = AsyncMock ()
854
- loop .run_until_complete (
855
- qubes .ext .utils .resolve_conflicts_and_attach (
856
- self .ext , {"1-1" : {front : assmnt , back : assmnt }}
857
+ with (mock .patch .object (self .ext , "attach_and_notify" )
858
+ as attach_and_notify ):
859
+ loop .run_until_complete (
860
+ qubes .ext .utils .resolve_conflicts_and_attach (
861
+ self .ext , {"1-1" : {front : assmnt , back : assmnt }}
862
+ )
857
863
)
858
- )
859
- self .ext .attach_and_notify .assert_called_once_with (front , assmnt )
864
+ attach_and_notify .assert_called_once_with (front , assmnt )
860
865
861
866
def test_016_on_qdb_change_ask (self ):
862
867
back , front = self .added_assign_setup ()
@@ -902,12 +907,13 @@ def test_020_on_startup_multiple_assignments_including_full(self):
902
907
qubesusbproxy .core3ext .USBDevice (Port (back , "1-1" , "usb" ))
903
908
)
904
909
905
- self .ext .attach_and_notify = AsyncMock ()
906
910
loop = asyncio .get_event_loop ()
907
- loop .run_until_complete (self .ext .on_domain_start (front , None ))
908
- self .assertEqual (
909
- self .ext .attach_and_notify .call_args [0 ][1 ].options , {"pid" : "did" }
910
- )
911
+ with (mock .patch .object (self .ext , "attach_and_notify" )
912
+ as attach_and_notify ):
913
+ loop .run_until_complete (self .ext .on_domain_start (front , None ))
914
+ self .assertEqual (
915
+ attach_and_notify .call_args [0 ][1 ].options , {"pid" : "did" }
916
+ )
911
917
912
918
def test_021_on_startup_multiple_assignments_port_vs_dev (self ):
913
919
back , front = self .added_assign_setup ()
@@ -933,11 +939,12 @@ def test_021_on_startup_multiple_assignments_port_vs_dev(self):
933
939
)
934
940
935
941
loop = asyncio .get_event_loop ()
936
- self .ext .attach_and_notify = AsyncMock ()
937
- loop .run_until_complete (self .ext .on_domain_start (front , None ))
938
- self .assertEqual (
939
- self .ext .attach_and_notify .call_args [0 ][1 ].options , {"pid" : "any" }
940
- )
942
+ with (mock .patch .object (self .ext , "attach_and_notify" )
943
+ as attach_and_notify ):
944
+ loop .run_until_complete (self .ext .on_domain_start (front , None ))
945
+ self .assertEqual (
946
+ attach_and_notify .call_args [0 ][1 ].options , {"pid" : "any" }
947
+ )
941
948
942
949
def test_022_on_startup_multiple_assignments_dev (self ):
943
950
back , front = self .added_assign_setup ()
@@ -965,12 +972,13 @@ def test_022_on_startup_multiple_assignments_dev(self):
965
972
qubesusbproxy .core3ext .USBDevice (Port (back , "1-2" , "usb" ))
966
973
)
967
974
968
- self .ext .attach_and_notify = AsyncMock ()
969
975
loop = asyncio .get_event_loop ()
970
- loop .run_until_complete (self .ext .on_domain_start (front , None ))
971
- self .assertEqual (
972
- self .ext .attach_and_notify .call_args [0 ][1 ].options , {"any" : "did" }
973
- )
976
+ with (mock .patch .object (self .ext , "attach_and_notify" )
977
+ as attach_and_notify ):
978
+ loop .run_until_complete (self .ext .on_domain_start (front , None ))
979
+ self .assertEqual (
980
+ attach_and_notify .call_args [0 ][1 ].options , {"any" : "did" }
981
+ )
974
982
975
983
def test_023_on_startup_already_attached (self ):
976
984
back , front = self .added_assign_setup (attachment = "sys-usb" )
@@ -983,10 +991,11 @@ def test_023_on_startup_already_attached(self):
983
991
front .devices ["usb" ]._assigned .append (assmnt )
984
992
back .devices ["usb" ]._exposed .append (exp_dev )
985
993
986
- self .ext .attach_and_notify = AsyncMock ()
987
994
loop = asyncio .get_event_loop ()
988
- loop .run_until_complete (self .ext .on_domain_start (front , None ))
989
- self .ext .attach_and_notify .assert_not_called ()
995
+ with (mock .patch .object (self .ext , "attach_and_notify" )
996
+ as attach_and_notify ):
997
+ loop .run_until_complete (self .ext .on_domain_start (front , None ))
998
+ attach_and_notify .assert_not_called ()
990
999
991
1000
992
1001
def list_tests ():
0 commit comments