"Fossies" - the Fresh Open Source Software Archive  

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

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

configuration_test.py  (pyre-check-0.0.53):configuration_test.py  (pyre-check-0.0.54)
skipping to change at line 13 skipping to change at line 13
# 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 site import site
import sys import sys
import unittest import unittest
from pathlib import Path from pathlib import Path
from typing import Any, NamedTuple, Optional, cast from typing import NamedTuple, Optional
from unittest.mock import MagicMock, PropertyMock, call, mock_open, patch from unittest.mock import MagicMock, PropertyMock, call, mock_open, patch
from .. import configuration from .. import configuration
from ..configuration import Configuration, InvalidConfiguration, SearchPathEleme nt from ..configuration import Configuration, InvalidConfiguration, SearchPathEleme nt
from ..exceptions import EnvironmentException
from ..find_directories import CONFIGURATION_FILE, LOCAL_CONFIGURATION_FILE from ..find_directories import CONFIGURATION_FILE, LOCAL_CONFIGURATION_FILE
class MockCompletedProcess(NamedTuple): class MockCompletedProcess(NamedTuple):
returncode: int returncode: int
stdout: str stdout: str
class ConfigurationIntegrationTest(unittest.TestCase): class ConfigurationIntegrationTest(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls) -> None: def setUpClass(cls) -> None:
# The Pyre environment variables change the outcome of tests. # The Pyre environment variables change the outcome of tests.
skipping to change at line 79 skipping to change at line 78
"source_directories": ["a"], "source_directories": ["a"],
"logger": "/usr/logger", "logger": "/usr/logger",
"ignore_all_errors": ["buck-out/dev/gen"], "ignore_all_errors": ["buck-out/dev/gen"],
}, },
{}, {},
] ]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre")) configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual(configuration.source_directories, ["a"]) self.assertEqual(configuration.source_directories, ["a"])
self.assertEqual(configuration.targets, []) self.assertEqual(configuration.targets, [])
self.assertEqual(configuration.logger, "/usr/logger") self.assertEqual(configuration.logger, "/usr/logger")
self.assertEqual( self.assertEqual(configuration.ignore_all_errors, ["buck-out/dev/gen"])
configuration.ignore_all_errors, ["/.pyre", "buck-out/dev/gen"]
)
self.assertEqual(configuration.file_hash, None) self.assertEqual(configuration.file_hash, None)
# Local configurations # Local configurations
json_load.side_effect = [ json_load.side_effect = [
{"source_directories": ["a"]}, {"source_directories": ["a"]},
{"source_directories": ["a"]}, {"source_directories": ["a"]},
{}, {},
] ]
with self.assertRaises(EnvironmentException): with self.assertRaises(InvalidConfiguration):
configuration = Configuration( configuration = Configuration(
"", local_root="local/path", dot_pyre_directory=Path("/.pyre") "", local_root="local/path", dot_pyre_directory=Path("/.pyre")
) )
self.assertEqual(configuration.source_directories, ["local/path/a"]) self.assertEqual(configuration.source_directories, ["local/path/a"])
json_load.side_effect = [{"source_directories": ["a"]}, {"version": "abc "}, {}] json_load.side_effect = [{"source_directories": ["a"]}, {"version": "abc "}, {}]
configuration = Configuration("local/path", dot_pyre_directory=Path("/.p yre")) configuration = Configuration("local/path", dot_pyre_directory=Path("/.p yre"))
self.assertEqual(configuration.source_directories, ["local/path/a"]) self.assertEqual(configuration.source_directories, ["local/path/a"])
self.assertEqual(configuration.ignore_all_errors, ["/.pyre"]) self.assertEqual(configuration.ignore_all_errors, [])
# Configuration fields # Configuration fields
json_load.side_effect = [{"targets": ["//a/b/c"], "disabled": 1}, {}] json_load.side_effect = [{"targets": ["//a/b/c"], "disabled": 1}, {}]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre")) configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual(configuration.targets, ["//a/b/c"]) self.assertEqual(configuration.targets, ["//a/b/c"])
self.assertEqual(configuration.source_directories, []) self.assertEqual(configuration.source_directories, [])
self.assertEqual(configuration.version_hash, "unversioned") self.assertEqual(configuration.version_hash, "unversioned")
self.assertEqual(configuration.logger, None) self.assertEqual(configuration.logger, None)
self.assertEqual(configuration.file_hash, None) self.assertEqual(configuration.file_hash, None)
self.assertTrue(configuration.disabled) self.assertTrue(configuration.disabled)
skipping to change at line 343 skipping to change at line 340
configuration.buck_builder_binary, "/root/some/dir/buck_builder" configuration.buck_builder_binary, "/root/some/dir/buck_builder"
) )
json_load.side_effect = [ json_load.side_effect = [
{"ignore_all_errors": ["abc/def", "/abc/def", "~/abc/def"]}, {"ignore_all_errors": ["abc/def", "/abc/def", "~/abc/def"]},
{}, {},
] ]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre")) configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual( self.assertEqual(
configuration.ignore_all_errors, configuration.ignore_all_errors,
["/.pyre", "/root/abc/def", "/abc/def", "/home/user/abc/def"], ["/root/abc/def", "/abc/def", "/home/user/abc/def"],
) )
json_load.side_effect = [ json_load.side_effect = [
{ {
"taint_models_path": ".pyre/taint_models", "taint_models_path": ".pyre/taint_models",
"search_path": "simple_string/", "search_path": "simple_string/",
"version": "VERSION", "version": "VERSION",
"typeshed": "/TYPE/%V/SHED/", "typeshed": "/TYPE/%V/SHED/",
}, },
{}, {},
skipping to change at line 495 skipping to change at line 492
json_load.side_effect = [{}, {}] json_load.side_effect = [{}, {}]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre")) configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertFalse(configuration.use_buck_builder) self.assertFalse(configuration.use_buck_builder)
# Test multiple definitions of the ignore_all_errors files. # Test multiple definitions of the ignore_all_errors files.
json_load.side_effect = [ json_load.side_effect = [
{"ignore_all_errors": ["buck-out/dev/gen"]}, {"ignore_all_errors": ["buck-out/dev/gen"]},
{"ignore_all_errors": ["buck-out/dev/gen2"]}, {"ignore_all_errors": ["buck-out/dev/gen2"]},
] ]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre")) configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual( self.assertEqual(configuration.ignore_all_errors, ["buck-out/dev/gen"])
configuration.ignore_all_errors, ["/.pyre", "buck-out/dev/gen"]
)
# Normalize number of workers if zero. # Normalize number of workers if zero.
json_load.side_effect = [{"typeshed": "/TYPESHED/", "workers": 0}, {}] json_load.side_effect = [{"typeshed": "/TYPESHED/", "workers": 0}, {}]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre")) configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual(configuration.typeshed, "/TYPESHED/") self.assertEqual(configuration.typeshed, "/TYPESHED/")
# Test excludes # Test excludes
json_load.side_effect = [{"exclude": "regexp"}, {}] json_load.side_effect = [{"exclude": "regexp"}, {}]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre")) configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual(configuration.excludes, ["regexp"]) self.assertEqual(configuration.excludes, ["regexp"])
skipping to change at line 541 skipping to change at line 536
configuration = Configuration("", dot_pyre_directory=Path("/.pyre")) configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual(configuration.autocomplete, True) self.assertEqual(configuration.autocomplete, True)
json_load.side_effect = [{}, {}] json_load.side_effect = [{}, {}]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre")) configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual(configuration.other_critical_files, []) self.assertEqual(configuration.other_critical_files, [])
json_load.side_effect = [{"critical_files": ["critical", "files"]}, {}] json_load.side_effect = [{"critical_files": ["critical", "files"]}, {}]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre")) configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual(configuration.other_critical_files, ["critical", "files "]) self.assertEqual(configuration.other_critical_files, ["critical", "files "])
json_load.side_effect = [{}, {}]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual(configuration.do_not_ignore_errors_in, [])
json_load.side_effect = [
{"do_not_ignore_errors_in": ["directory1", "directory2"]},
{},
]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual(
configuration.do_not_ignore_errors_in, ["directory1", "directory2"]
)
@patch("os.path.isfile") @patch("os.path.isfile")
@patch("os.path.isdir") @patch("os.path.isdir")
@patch("os.path.exists") @patch("os.path.exists")
@patch("os.access") @patch("os.access")
# Need to patch this method because this test messes around with # Need to patch this method because this test messes around with
# isfile/isdir via the patches above. When test optimizations are # isfile/isdir via the patches above. When test optimizations are
# applied, _apply_defaults goes crazy; hence mock it so it doesn't # applied, _apply_defaults goes crazy; hence mock it so it doesn't
# run - it's not important for this test anyway. # run - it's not important for this test anyway.
@patch.object(Configuration, "_apply_defaults") @patch.object(Configuration, "_apply_defaults")
@patch.object(Configuration, "_validate") @patch.object(Configuration, "_validate")
skipping to change at line 678 skipping to change at line 685
) -> None: ) -> None:
# Do not expand test paths against real filesystem # Do not expand test paths against real filesystem
expand_relative_path.side_effect = lambda root, path: path expand_relative_path.side_effect = lambda root, path: path
# Assume all paths are valid. # Assume all paths are valid.
os_access.return_value = True os_access.return_value = True
os_path_exists.return_value = True os_path_exists.return_value = True
# Properly ignored nested local configurations. # Properly ignored nested local configurations.
find_parent_directory_containing_file.side_effect = [Path("root"), None] find_parent_directory_containing_file.side_effect = [Path("root"), None]
path_resolve.side_effect = [ path_resolve.side_effect = [Path("root/local"), Path("root/local")]
Path("root/local"),
Path("/.pyre"),
Path("root/local"),
]
os_path_isdir.return_value = True os_path_isdir.return_value = True
os_path_isfile.return_value = False os_path_isfile.return_value = False
json_loads.side_effect = [ json_loads.side_effect = [
{ {
"source_directories": ["a"], "source_directories": ["a"],
"binary": "abc", "binary": "abc",
"logger": "/usr/logger", "logger": "/usr/logger",
"version": "VERSION", "version": "VERSION",
"typeshed": "TYPE/%V/SHED/", "typeshed": "TYPE/%V/SHED/",
"strict": False, "strict": False,
skipping to change at line 747 skipping to change at line 750
"source_directories": ["a"], "source_directories": ["a"],
"binary": "abc", "binary": "abc",
"logger": "/usr/logger", "logger": "/usr/logger",
"version": "VERSION", "version": "VERSION",
"typeshed": "TYPE/%V/SHED/", "typeshed": "TYPE/%V/SHED/",
"strict": False, "strict": False,
"extensions": [".a", ".b", ""], "extensions": [".a", ".b", ""],
}, },
{}, {},
] ]
with self.assertRaises(EnvironmentException): with self.assertRaises(InvalidConfiguration):
Configuration( Configuration(
project_root="root", project_root="root",
local_root="root/local", local_root="root/local",
dot_pyre_directory=Path("/.pyre"), dot_pyre_directory=Path("/.pyre"),
) )
# Project and local configurations both specifying sources. # Project and local configurations both specifying sources.
path_resolve.reset_mock() path_resolve.reset_mock()
find_parent_directory_containing_file.side_effect = [None, None] find_parent_directory_containing_file.side_effect = [None, None]
json_loads.side_effect = [ json_loads.side_effect = [
skipping to change at line 773 skipping to change at line 776
{ {
"source_directories": ["project_sources"], "source_directories": ["project_sources"],
"binary": "abc", "binary": "abc",
"logger": "/usr/logger", "logger": "/usr/logger",
"version": "VERSION", "version": "VERSION",
"typeshed": "TYPE/%V/SHED/", "typeshed": "TYPE/%V/SHED/",
"strict": False, "strict": False,
"extensions": [".a", ".b", ""], "extensions": [".a", ".b", ""],
}, },
] ]
with self.assertRaises(EnvironmentException): with self.assertRaises(InvalidConfiguration):
Configuration( Configuration(
project_root="root", project_root="root",
local_root="root/local", local_root="root/local",
dot_pyre_directory=Path("/.pyre"), dot_pyre_directory=Path("/.pyre"),
) )
@patch("os.path.isfile") @patch("os.path.isfile")
@patch("os.path.isdir") @patch("os.path.isdir")
@patch("os.path.exists") @patch("os.path.exists")
@patch.object(Configuration, "_validate") @patch.object(Configuration, "_validate")
def test_nonexisting_local_configuration( def test_nonexisting_local_configuration(
self, configuration_validate, os_path_exists, os_path_isdir, os_path_isf ile self, configuration_validate, os_path_exists, os_path_isdir, os_path_isf ile
) -> None: ) -> None:
# Test that a non-existing local configuration directory was provided. # Test that a non-existing local configuration directory was provided.
os_path_exists.return_value = False os_path_exists.return_value = False
os_path_isdir.return_value = True os_path_isdir.return_value = True
os_path_isfile.return_value = False os_path_isfile.return_value = False
with self.assertRaises(EnvironmentException): with self.assertRaises(InvalidConfiguration):
Configuration( Configuration(
project_root="/", local_root="local", dot_pyre_directory=Path("/ .pyre") project_root="/", local_root="local", dot_pyre_directory=Path("/ .pyre")
) )
# Test that a non-existing local configuration file was provided. # Test that a non-existing local configuration file was provided.
os_path_exists.return_value = False os_path_exists.return_value = False
os_path_isdir.return_value = False os_path_isdir.return_value = False
os_path_isfile.return_value = True os_path_isfile.return_value = True
with self.assertRaises(EnvironmentException): with self.assertRaises(InvalidConfiguration):
Configuration( Configuration(
project_root="/", project_root="/",
local_root="local/.some_configuration", local_root="local/.some_configuration",
dot_pyre_directory=Path("/.pyre"), dot_pyre_directory=Path("/.pyre"),
) )
with self.assertRaises(EnvironmentException): with self.assertRaises(InvalidConfiguration):
Configuration( Configuration(
project_root="/", project_root="/",
local_root="local/.some_configuration", local_root="local/.some_configuration",
dot_pyre_directory=Path("/.pyre"), dot_pyre_directory=Path("/.pyre"),
) )
# Test an existing local directory, without a configuration file. # Test an existing local directory, without a configuration file.
os_path_exists.side_effect = lambda path: not path.endswith(".local") os_path_exists.side_effect = lambda path: not path.endswith(".local")
os_path_isdir.return_value = lambda path: not path.endswith(".local") os_path_isdir.return_value = lambda path: not path.endswith(".local")
os_path_isfile.return_value = lambda path: path.endswith(".local") os_path_isfile.return_value = lambda path: path.endswith(".local")
with self.assertRaises(EnvironmentException): with self.assertRaises(InvalidConfiguration):
Configuration( Configuration(
project_root="/", project_root="/",
local_root="localdir", local_root="localdir",
dot_pyre_directory=Path("/.pyre"), dot_pyre_directory=Path("/.pyre"),
) )
with self.assertRaises(EnvironmentException): with self.assertRaises(InvalidConfiguration):
Configuration( Configuration(
project_root="/", project_root="/",
local_root="localdir", local_root="localdir",
dot_pyre_directory=Path("/.pyre"), dot_pyre_directory=Path("/.pyre"),
) )
@patch("os.path.abspath", side_effect=lambda path: path) @patch("os.path.abspath", side_effect=lambda path: path)
@patch("os.path.isdir", return_value=True) @patch("os.path.isdir", return_value=True)
@patch("os.path.exists") @patch("os.path.exists")
@patch("os.access", return_value=True) @patch("os.access", return_value=True)
skipping to change at line 874 skipping to change at line 877
"strict": False, "strict": False,
"ignore_all_errors": ["buck-out/dev/gen"], "ignore_all_errors": ["buck-out/dev/gen"],
"extensions": [".a", ".b", ""], "extensions": [".a", ".b", ""],
}, },
{}, {},
] ]
Configuration("", dot_pyre_directory=Path("/.pyre")) Configuration("", dot_pyre_directory=Path("/.pyre"))
except BaseException: except BaseException:
self.fail("Configuration should not raise.") self.fail("Configuration should not raise.")
with self.assertRaises(EnvironmentException): with self.assertRaises(InvalidConfiguration):
json_loads.side_effect = [ json_loads.side_effect = [
{ {
"source_directories": ["a"], "source_directories": ["a"],
"binary": "abc", "binary": "abc",
"logger": "/usr/logger", "logger": "/usr/logger",
"version": "VERSION", "version": "VERSION",
"typeshed": "TYPE/%V/SHED/", "typeshed": "TYPE/%V/SHED/",
"ignore_all_errors": ["buck-out/dev/gen"], "ignore_all_errors": ["buck-out/dev/gen"],
"extensions": [".a", "b"], "extensions": [".a", "b"],
}, },
 End of changes. 17 change blocks. 
24 lines changed or deleted 27 lines changed or added

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