"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "client/commands/tests/initialize_test.py" between
pyre-check-0.0.54.tar.gz and pyre-check-0.0.55.tar.gz

About: Pyre is a performant type checker for Python (ships with Pysa, a security focused static analysis tool).

initialize_test.py  (pyre-check-0.0.54):initialize_test.py  (pyre-check-0.0.55)
# Copyright (c) Facebook, Inc. and its affiliates. # Copyright (c) Facebook, Inc. and its affiliates.
# #
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
# pyre-unsafe # pyre-unsafe
import os import os
import subprocess
import sys import sys
import unittest import unittest
from pathlib import Path
from unittest.mock import call, mock_open, patch from unittest.mock import call, mock_open, patch
from ... import commands
from ...commands import initialize from ...commands import initialize
from ...commands.initialize import log from ...commands.initialize import log
from ...exceptions import EnvironmentException
from .command_test import mock_arguments
class InitializeTest(unittest.TestCase): class InitializeTest(unittest.TestCase):
@patch.object(os, "getcwd", return_value="/original/directory") @patch.object(os, "getcwd", return_value="/original/directory")
@patch.object(log, "get_yes_no_input", return_value=True) @patch.object(log, "get_yes_no_input", return_value=True)
@patch.object(log, "get_optional_input", return_value="") @patch.object(log, "get_optional_input", return_value="")
# pyre-fixme[56]: Argument `tools.pyre.client.commands.initialize.log` to # pyre-fixme[56]: Argument `tools.pyre.client.commands.initialize.log` to
# decorator factory `unittest.mock.patch.object` could not be resolved in a global # decorator factory `unittest.mock.patch.object` could not be resolved in a global
# scope. # scope.
@patch.object(log, "get_input", return_value="") @patch.object(log, "get_input", return_value="")
@patch("shutil.which") @patch("shutil.which")
@patch("os.path.isfile") @patch("os.path.isfile")
@patch("subprocess.call") @patch("subprocess.run")
@patch("builtins.open") @patch("builtins.open")
def test_initialize( def test_initialize(
self, self,
open, open,
subprocess_call, subprocess_run,
isfile, isfile,
which, which,
_get_input, _get_input,
_get_optional_input, _get_optional_input,
get_yes_no_input, get_yes_no_input,
getcwd, getcwd,
) -> None: ) -> None:
get_yes_no_input.return_value = True get_yes_no_input.return_value = True
def exists(path): def exists(path):
skipping to change at line 56 skipping to change at line 55
return False return False
elif path.endswith(".pyre_configuration"): elif path.endswith(".pyre_configuration"):
return False return False
elif path.endswith(".pyre_configuration.local"): elif path.endswith(".pyre_configuration.local"):
return False return False
else: else:
return True return True
isfile.side_effect = exists isfile.side_effect = exists
# One for shutil.which("watchman"), another for shutil.which(BINARY_NAME ). # One for shutil.which("watchman"), another for shutil.which(BINARY_NAME ).
which.side_effect = [True, True] which.side_effect = ["watchman", "binary"]
with patch.object(commands.Command, "_call_client"), patch.object( with patch.object(initialize, "find_typeshed", return_value=Path("/tmp")
initialize, "find_typeshed", return_value="/tmp" ):
):
initialize.Initialize().run() initialize.Initialize().run()
subprocess_call.assert_has_calls([call(["watchman", "watch-project", subprocess_run.assert_has_calls(
"."])]) [
call(
["watchman", "watch-project", "."],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
]
)
open.assert_any_call(os.path.abspath(".watchmanconfig"), "w+") open.assert_any_call(os.path.abspath(".watchmanconfig"), "w+")
def exists(path): def exists(path):
return False return False
isfile.side_effect = exists isfile.side_effect = exists
file = mock_open() file = mock_open()
with patch("builtins.open", file), patch.object( with patch("builtins.open", file), patch.object(
commands.Command, "_call_client"
), patch.object(
initialize.Initialize, "_get_local_configuration", return_value={} initialize.Initialize, "_get_local_configuration", return_value={}
), patch.object( ), patch.object(initialize.Initialize, "_is_local", return_value=True):
initialize.Initialize, "_is_local", return_value=True
):
initialize.Initialize().run() initialize.Initialize().run()
file().write.assert_has_calls([call("{}"), call("\n")]) file().write.assert_has_calls([call("{}"), call("\n")])
def exists(path): with patch.object(sys, "argv", ["/tmp/pyre/bin/pyre"]), patch.object(
if path.endswith(".pyre_configuration"): initialize, "find_typeshed", return_value=Path("/tmp")
return True ):
return False
isfile.side_effect = exists
with patch.object(commands.Command, "_call_client"):
with self.assertRaises(EnvironmentException):
initialize.Initialize().run()
with patch.object(commands.Command, "_call_client"), patch.object(
sys, "argv", ["/tmp/pyre/bin/pyre"]
), patch.object(initialize, "find_typeshed", return_value="/tmp"):
which.reset_mock() which.reset_mock()
which.side_effect = [True, None, "/tmp/pyre/bin/pyre.bin"] which.side_effect = [True, None, "/tmp/pyre/bin/pyre.bin"]
initialize.Initialize()._get_configuration() initialize.Initialize()._get_configuration()
which.assert_has_calls( which.assert_has_calls(
[call("watchman"), call("pyre.bin"), call("/tmp/pyre/bin/pyre.bi n")] [call("watchman"), call("pyre.bin"), call("/tmp/pyre/bin/pyre.bi n")]
) )
def test_get_local_configuration(self) -> None: def test_get_local_configuration(self) -> None:
command = initialize.Initialize() command = initialize.Initialize()
 End of changes. 11 change blocks. 
29 lines changed or deleted 22 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)