2019-06-06 14:18:00 +02:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io;
|
|
|
|
|
2019-08-11 23:51:13 +02:00
|
|
|
use ansi_term::Color;
|
2019-10-15 16:01:44 +02:00
|
|
|
use tempfile;
|
2019-08-11 23:51:13 +02:00
|
|
|
|
2020-04-14 10:26:51 +02:00
|
|
|
use crate::common::{self, TestCommand};
|
2019-06-06 14:18:00 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_python_version() -> io::Result<()> {
|
2019-10-15 16:01:44 +02:00
|
|
|
let dir = tempfile::tempdir()?;
|
2019-10-15 17:10:16 +02:00
|
|
|
File::create(dir.path().join(".python-version"))?.sync_all()?;
|
2019-06-06 14:18:00 +02:00
|
|
|
|
|
|
|
let output = common::render_module("python")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-01-18 02:43:29 +01:00
|
|
|
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
|
2019-06-06 14:18:00 +02:00
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 18:12:25 +01:00
|
|
|
dir.close()
|
2019-06-06 14:18:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_requirements_txt() -> io::Result<()> {
|
2019-10-15 16:01:44 +02:00
|
|
|
let dir = tempfile::tempdir()?;
|
2019-10-15 17:10:16 +02:00
|
|
|
File::create(dir.path().join("requirements.txt"))?.sync_all()?;
|
2019-06-06 14:18:00 +02:00
|
|
|
|
|
|
|
let output = common::render_module("python")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-01-18 02:43:29 +01:00
|
|
|
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
|
2019-06-06 14:18:00 +02:00
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 18:12:25 +01:00
|
|
|
dir.close()
|
2019-06-06 14:18:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_pyproject_toml() -> io::Result<()> {
|
2019-10-15 16:01:44 +02:00
|
|
|
let dir = tempfile::tempdir()?;
|
2019-10-15 17:10:16 +02:00
|
|
|
File::create(dir.path().join("pyproject.toml"))?.sync_all()?;
|
2019-06-06 14:18:00 +02:00
|
|
|
|
|
|
|
let output = common::render_module("python")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-01-18 02:43:29 +01:00
|
|
|
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
|
2019-06-06 14:18:00 +02:00
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 18:12:25 +01:00
|
|
|
dir.close()
|
2019-06-06 14:18:00 +02:00
|
|
|
}
|
|
|
|
|
2019-08-22 00:54:22 +02:00
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_pipfile() -> io::Result<()> {
|
2019-10-15 16:01:44 +02:00
|
|
|
let dir = tempfile::tempdir()?;
|
2019-10-15 17:10:16 +02:00
|
|
|
File::create(dir.path().join("Pipfile"))?.sync_all()?;
|
2019-08-22 00:54:22 +02:00
|
|
|
|
|
|
|
let output = common::render_module("python")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-01-18 02:43:29 +01:00
|
|
|
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
|
2019-08-22 00:54:22 +02:00
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 18:12:25 +01:00
|
|
|
dir.close()
|
2019-09-15 18:21:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_tox() -> io::Result<()> {
|
2019-10-15 16:01:44 +02:00
|
|
|
let dir = tempfile::tempdir()?;
|
2019-10-15 17:10:16 +02:00
|
|
|
File::create(dir.path().join("tox.ini"))?.sync_all()?;
|
2019-09-15 18:21:40 +02:00
|
|
|
|
|
|
|
let output = common::render_module("python")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-01-18 02:43:29 +01:00
|
|
|
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
|
2019-09-15 18:21:40 +02:00
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 18:12:25 +01:00
|
|
|
dir.close()
|
2019-08-22 00:54:22 +02:00
|
|
|
}
|
|
|
|
|
2020-04-14 10:26:51 +02:00
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_setup_py() -> io::Result<()> {
|
|
|
|
let dir = tempfile::tempdir()?;
|
|
|
|
File::create(dir.path().join("setup.py"))?.sync_all()?;
|
|
|
|
|
|
|
|
let output = common::render_module("python")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-04-14 14:48:10 +02:00
|
|
|
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
|
2020-04-14 10:26:51 +02:00
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_init_py() -> io::Result<()> {
|
|
|
|
let dir = tempfile::tempdir()?;
|
|
|
|
File::create(dir.path().join("__init__.py"))?.sync_all()?;
|
|
|
|
|
|
|
|
let output = common::render_module("python")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-04-14 14:48:10 +02:00
|
|
|
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
|
2020-04-14 10:26:51 +02:00
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-06-06 14:18:00 +02:00
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_py_file() -> io::Result<()> {
|
2019-10-15 16:01:44 +02:00
|
|
|
let dir = tempfile::tempdir()?;
|
2019-10-15 17:10:16 +02:00
|
|
|
File::create(dir.path().join("main.py"))?.sync_all()?;
|
2019-06-06 14:18:00 +02:00
|
|
|
|
|
|
|
let output = common::render_module("python")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-01-18 02:43:29 +01:00
|
|
|
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
|
2019-06-06 14:18:00 +02:00
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 18:12:25 +01:00
|
|
|
dir.close()
|
2019-06-06 14:18:00 +02:00
|
|
|
}
|
2019-08-11 23:51:13 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn with_virtual_env() -> io::Result<()> {
|
2019-10-15 16:01:44 +02:00
|
|
|
let dir = tempfile::tempdir()?;
|
2019-10-15 17:10:16 +02:00
|
|
|
File::create(dir.path().join("main.py"))?.sync_all()?;
|
2019-08-11 23:51:13 +02:00
|
|
|
let output = common::render_module("python")
|
|
|
|
.env("VIRTUAL_ENV", "/foo/bar/my_venv")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-01-18 02:43:29 +01:00
|
|
|
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6 (my_venv)"));
|
2019-08-11 23:51:13 +02:00
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 18:12:25 +01:00
|
|
|
dir.close()
|
2019-08-11 23:51:13 +02:00
|
|
|
}
|
2019-11-02 12:10:21 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn with_active_venv() -> io::Result<()> {
|
|
|
|
let dir = tempfile::tempdir()?;
|
|
|
|
|
|
|
|
let output = common::render_module("python")
|
|
|
|
.env("VIRTUAL_ENV", "/foo/bar/my_venv")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-01-18 02:43:29 +01:00
|
|
|
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6 (my_venv)"));
|
2019-11-02 12:10:21 +01:00
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 18:12:25 +01:00
|
|
|
dir.close()
|
2019-11-02 12:10:21 +01:00
|
|
|
}
|
2020-04-14 10:26:51 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn disabled_scan_for_pyfiles_and_folder_with_ignored_py_file() -> io::Result<()> {
|
|
|
|
let dir = tempfile::tempdir()?;
|
|
|
|
File::create(dir.path().join("foo.py"))?.sync_all()?;
|
|
|
|
|
|
|
|
let output = common::render_module("python")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[python]
|
|
|
|
scan_for_pyfiles = false
|
|
|
|
})
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
|
|
|
let expected = "";
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn disabled_scan_for_pyfiles_and_folder_with_setup_py() -> io::Result<()> {
|
|
|
|
let dir = tempfile::tempdir()?;
|
|
|
|
File::create(dir.path().join("setup.py"))?.sync_all()?;
|
|
|
|
|
|
|
|
let output = common::render_module("python")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[python]
|
|
|
|
scan_for_pyfiles = false
|
|
|
|
})
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-04-14 14:48:10 +02:00
|
|
|
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
|
2020-04-14 10:26:51 +02:00
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|