def test_redundant_magic(self): with file_utils.Tempdir() as d: d.create_file("foo.py") d.create_file("bar/baz.py") with file_utils.cd(d.path): self.assertPathsEqual(compat.recursive_glob("**/**/*.py"), ["foo.py", "bar/baz.py"])
def test_nested_magic(self): with file_utils.Tempdir() as d: d.create_file("foo/bar.py") d.create_file("foo/baz/qux.py") with file_utils.cd(d.path): self.assertPathsEqual(compat.recursive_glob("foo/**/*.py"), ["foo/bar.py", "foo/baz/qux.py"])
def testCd(self): with file_utils.Tempdir() as d: d.create_directory("foo") d1 = os.getcwd() with file_utils.cd(d.path): self.assertTrue(os.path.isdir("foo")) d2 = os.getcwd() self.assertEqual(d1, d2)
def test_cwd(self): with file_utils.Tempdir() as d: fs = [d.create_file(f) for f in self.FILES] pyfiles = [f for f in fs if f.endswith(".py")] # cd to d.path and run with just "." as an argument with file_utils.cd(d.path): self.assertItemsEqual(pyfiles, file_utils.expand_source_files("."))
def test_expand(self): filenames = ["a.py", "b/c.py"] with file_utils.Tempdir() as d: for f in filenames: d.create_file(f) with file_utils.cd(d.path): self.assertEqual(file_utils.expand_globpaths(["**/*.py"]), [os.path.realpath(f) for f in filenames])
def test_setup_cfg_from_subdir(self): with file_utils.Tempdir() as d: d.create_file('setup.cfg', SETUP_CFG) sub = d.create_directory('x/y/z') conf = config.Config() with file_utils.cd(sub): conf = config.read_config_file_or_die(None) self._validate_file_contents(conf, d.path)
def test_parse_exclude_dir(self): filenames = ['foo/f1.py', 'foo/f2.py'] with file_utils.Tempdir() as d: for f in filenames: d.create_file(f) with file_utils.cd(d.path): args = self.parser.parse_args(['--exclude=foo/']) self.assertEqual(args.exclude, {os.path.realpath(f) for f in filenames})
def test_parse_single_exclude(self): filenames = ['a.py', 'b/c.py'] with file_utils.Tempdir() as d: for f in filenames: d.create_file(f) with file_utils.cd(d.path): args = self.parser.parse_args(['--exclude=**/*.py']) self.assertEqual(args.exclude, {os.path.realpath(f) for f in filenames})
def test_magic(self): filenames = ["a.py", "b/c.py"] with file_utils.Tempdir() as d: for f in filenames: d.create_file(f) with file_utils.cd(d.path): self.assertEqual(file_utils.expand_source_files("**/*.py"), {os.path.realpath(f) for f in filenames})
def test_multiple_magic(self): with file_utils.Tempdir() as d: d.create_file("d1/d2/d3/f1.py") d.create_file("d1/d2/f2.py") d.create_file("d2/f3.py") d.create_file("d2/d3/f4.py") with file_utils.cd(d.path): self.assertPathsEqual(compat.recursive_glob("**/d2/**/*.py"), [ "d1/d2/d3/f1.py", "d1/d2/f2.py", "d2/f3.py", "d2/d3/f4.py" ])
def test_generate(self): conf = config.FileConfig() with file_utils.Tempdir() as d: f = os.path.join(d.path, 'sample.cfg') config.generate_sample_config_or_die(f, self._pytype_single_args) # Test that we've generated a valid config and spot-check a pytype-all # and a pytype-single argument. conf.read_from_file(f) with file_utils.cd(d.path): expected_pythonpath = [ os.path.realpath(p) for p in config.ITEMS['pythonpath'].sample.split(os.pathsep)] expected_protocols = config._PYTYPE_SINGLE_ITEMS['protocols'].sample self.assertEqual(conf.pythonpath, expected_pythonpath) self.assertEqual(conf.protocols, expected_protocols)
def test_cd_noop(self): d = os.getcwd() with file_utils.cd(None): self.assertEqual(os.getcwd(), d) with file_utils.cd(""): self.assertEqual(os.getcwd(), d)
def test_simple_magic(self): with file_utils.Tempdir() as d: d.create_file("foo.py") with file_utils.cd(d.path): self.assertPathsEqual(compat.recursive_glob("*.py"), ["foo.py"])
def test_missing_setup_cfg_section(self): with file_utils.Tempdir() as d: d.create_file('setup.cfg', RANDOM_CFG) with file_utils.cd(d.path): conf = config.read_config_file_or_die(None) self._validate_empty_contents(conf)
def test_setup_cfg(self): with file_utils.Tempdir() as d: d.create_file('setup.cfg', SETUP_CFG) with file_utils.cd(d.path): conf = config.read_config_file_or_die(None) self._validate_file_contents(conf, d.path)