"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "client/tests/configuration_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).

configuration_test.py  (pyre-check-0.0.54):configuration_test.py  (pyre-check-0.0.55)
skipping to change at line 17 skipping to change at line 17
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 NamedTuple, Optional 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 from ..configuration import (
nt Configuration,
InvalidConfiguration,
SearchPathElement,
_relativize_root,
)
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 78 skipping to change at line 83
"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(configuration.ignore_all_errors, ["buck-out/dev/gen"]) self.assertEqual(configuration._ignore_all_errors, ["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(InvalidConfiguration): 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, []) 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 339 skipping to change at line 344
self.assertEqual( self.assertEqual(
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,
["/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 492 skipping to change at line 497
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(configuration.ignore_all_errors, ["buck-out/dev/gen"]) self.assertEqual(configuration._ignore_all_errors, ["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 538 skipping to change at line 543
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 = [{}, {}] json_load.side_effect = [{}, {}]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre")) configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual(configuration.do_not_ignore_errors_in, []) self.assertEqual(configuration._do_not_ignore_errors_in, [])
json_load.side_effect = [ json_load.side_effect = [
{"do_not_ignore_errors_in": ["directory1", "directory2"]}, {"do_not_ignore_errors_in": ["directory1", "directory2"]},
{}, {},
] ]
configuration = Configuration("", dot_pyre_directory=Path("/.pyre")) configuration = Configuration("", dot_pyre_directory=Path("/.pyre"))
self.assertEqual( self.assertEqual(
configuration.do_not_ignore_errors_in, ["directory1", "directory2"] 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.
skipping to change at line 942 skipping to change at line 947
self.assertEqual(expected, configuration.get_binary_version()) self.assertEqual(expected, configuration.get_binary_version())
assert_version( assert_version(
returncode=0, stdout="facefacefaceb00", expected="facefacefaceb00" returncode=0, stdout="facefacefaceb00", expected="facefacefaceb00"
) )
assert_version( assert_version(
returncode=0, stdout=" facefacefaceb00\n", expected="facefacefaceb00 " returncode=0, stdout=" facefacefaceb00\n", expected="facefacefaceb00 "
) )
assert_version(returncode=1, stdout="facefacefaceb00", expected=None) assert_version(returncode=1, stdout="facefacefaceb00", expected=None)
def test_relativize_root__project_relative_path(self) -> None:
self.assertEqual(
_relativize_root("//foo/bar.py", project_root="hello", relative_root
=None),
"hello/foo/bar.py",
)
# Globs should be untouched.
self.assertEqual(
_relativize_root(
"//foo/*/bar.py", project_root="hello", relative_root=None
),
"hello/foo/*/bar.py",
)
def test_relativize_root__not_project_relative(self) -> None:
self.assertEqual(
_relativize_root("foo/bar.py", project_root="hello", relative_root=N
one),
"foo/bar.py",
)
# Globs should be untouched.
self.assertEqual(
_relativize_root("foo/*/bar.py", project_root="hello", relative_root
=None),
"foo/*/bar.py",
)
class SearchPathElementTest(unittest.TestCase): class SearchPathElementTest(unittest.TestCase):
@patch("os.path.isdir", return_value=True) @patch("os.path.isdir", return_value=True)
def test_expand(self, isdir) -> None: def test_expand(self, isdir) -> None:
element = SearchPathElement.expand(path="simple/path", project_root="roo t") element = SearchPathElement.expand(path="simple/path", project_root="roo t")
self.assertEqual(element.path(), "simple/path") self.assertEqual(element.path(), "simple/path")
self.assertEqual(element.subdirectory, None) self.assertEqual(element.subdirectory, None)
element = SearchPathElement.expand( element = SearchPathElement.expand(
path="simple/path", path="simple/path",
project_root="root", project_root="root",
 End of changes. 8 change blocks. 
8 lines changed or deleted 39 lines changed or added

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