1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15-
1615import unittest
1716import subprocess
1817import os
2827class CommandLogger (monitoring .CommandListener ):
2928 def __init__ (self ):
3029 self .cmd_payload = {}
30+
3131 def started (self , event ):
3232 self .cmd_payload = event .command
3333
@@ -37,6 +37,7 @@ def succeeded(self, event):
3737 def failed (self , event ):
3838 pass
3939
40+
4041class TestExplainableCollection (unittest .TestCase ):
4142 def setUp (self ) -> None :
4243 self .logger = CommandLogger ()
@@ -217,6 +218,25 @@ def test_imports(self):
217218 from pymongoexplain import ExplainableCollection
218219 self .assertEqual (ExplainableCollection , ExplainCollection )
219220
221+ def test_verbosity (self ):
222+ res = self .explain .find ({})
223+ self .assertNotIn ("executionStats" , res )
224+ self .assertNotIn ("allPlansExecution" , res .get ("executionStats" , []))
225+ self .explain = ExplainCollection (self .collection , verbosity = "executionStats" )
226+ res = self .explain .find ({})
227+ self .assertIn ("executionStats" , res )
228+ self .assertNotIn ("allPlansExecution" , res ["executionStats" ])
229+ self .explain = ExplainCollection (self .collection , verbosity = "allPlansExecution" )
230+ res = self .explain .find ({})
231+ self .assertIn ("executionStats" , res )
232+ self .assertIn ("allPlansExecution" , res ["executionStats" ])
233+
234+ def test_comment (self ):
235+ self .explain .find ({})
236+ self .assertNotIn ("comment" , self .logger .cmd_payload )
237+ self .explain = ExplainCollection (self .collection , comment = "comment" )
238+ self .explain .find ({})
239+ self .assertIn ("comment" , self .logger .cmd_payload )
220240
221241if __name__ == '__main__' :
222242 unittest .main ()
0 commit comments