def test_distribution_files_additional_files(): """ Test setup.py and tests discovery. """ dist = Distribution() with change_dir(os.path.join(TEST_PATH, "..")): dist.packages = find_packages() files = FormatCommand(dist).distribution_files() # Ensure data is appended to fake_package assert set(files) == {"setup.py", "setuptools_black", "tests"}
def test_distribution_files_package_dir(): """ Test packages collection when pacakge_dir is used to get packages from sub-directory. """ dist = Distribution() with change_dir(TEST_PATH): dist.packages = find_packages("data") dist.package_dir = {"": "data"} files = FormatCommand(dist).distribution_files() # Ensure data is appended to fake_package assert list(files) == [os.path.join("data", "fake_package")]
def test_run_check(run_mock: mock.Mock): """ Test check-only run. """ dist = Distribution() with change_dir(TEST_PATH): dist.packages = find_packages("data") command = FormatCommand(dist) command.check = True command.run() run_mock.assert_called_with( [sys.executable, "-m", "black", "--check", "fake_package"], check=True, env=mock.ANY, )
def test_run(run_mock: mock.Mock): """ Test basic usage, only relying on find_packages to fill setup packages, with no setup.py nor tests. """ dist = Distribution() # Switch to fake project's root with change_dir(TEST_PATH): dist.packages = find_packages("data") FormatCommand(dist).run() run_mock.assert_called_with( [sys.executable, "-m", "black", "fake_package"], check=True, env=mock.ANY, )