public void IsPythonFile() { foreach (var test in new[] { new { SourceFile = @"spam\abc.py", ExpectedStrict = true, ExpectedNoStrict = true, ExpectedWithoutCompiled = true, ExpectedWithoutCache = true }, new { SourceFile = @"spam\abc.pyc", ExpectedStrict = true, ExpectedNoStrict = true, ExpectedWithoutCompiled = true, ExpectedWithoutCache = false }, new { SourceFile = @"spam\abc.pyo", ExpectedStrict = true, ExpectedNoStrict = true, ExpectedWithoutCompiled = true, ExpectedWithoutCache = false }, new { SourceFile = @"spam\abc.pyd", ExpectedStrict = true, ExpectedNoStrict = true, ExpectedWithoutCompiled = false, ExpectedWithoutCache = true }, new { SourceFile = @"spam\abc.cp35-win_amd64.pyd", ExpectedStrict = true, ExpectedNoStrict = true, ExpectedWithoutCompiled = false, ExpectedWithoutCache = true }, new { SourceFile = @"spam\abc_d.pyd", ExpectedStrict = true, ExpectedNoStrict = true, ExpectedWithoutCompiled = false, ExpectedWithoutCache = true }, new { SourceFile = @"spam\abc_d.cp35-win_amd64.pyd", ExpectedStrict = true, ExpectedNoStrict = true, ExpectedWithoutCompiled = false, ExpectedWithoutCache = true }, new { SourceFile = @"spam\abc-123.py", ExpectedStrict = false, ExpectedNoStrict = true, ExpectedWithoutCompiled = true, ExpectedWithoutCache = true }, new { SourceFile = @"spam\abc-123.pyc", ExpectedStrict = false, ExpectedNoStrict = true, ExpectedWithoutCompiled = true, ExpectedWithoutCache = false }, new { SourceFile = @"spam\abc-123.pyo", ExpectedStrict = false, ExpectedNoStrict = true, ExpectedWithoutCompiled = true, ExpectedWithoutCache = false }, new { SourceFile = @"spam\abc-123.pyd", ExpectedStrict = false, ExpectedNoStrict = true, ExpectedWithoutCompiled = false, ExpectedWithoutCache = true }, new { SourceFile = @"spam\abc.123.py", ExpectedStrict = false, ExpectedNoStrict = true, ExpectedWithoutCompiled = true, ExpectedWithoutCache = true }, new { SourceFile = @"spam\abc.123.pyc", ExpectedStrict = true, ExpectedNoStrict = true, ExpectedWithoutCompiled = true, ExpectedWithoutCache = false }, new { SourceFile = @"spam\abc.123.pyo", ExpectedStrict = true, ExpectedNoStrict = true, ExpectedWithoutCompiled = true, ExpectedWithoutCache = false }, new { SourceFile = @"spam\abc.123.pyd", ExpectedStrict = true, ExpectedNoStrict = true, ExpectedWithoutCompiled = false, ExpectedWithoutCache = true }, }) { Assert.AreEqual(test.ExpectedStrict, ModulePath.IsPythonFile(test.SourceFile, true, true, true), test.SourceFile); Assert.AreEqual(test.ExpectedNoStrict, ModulePath.IsPythonFile(test.SourceFile, false, true, true), test.SourceFile); Assert.AreEqual(test.ExpectedWithoutCompiled, ModulePath.IsPythonFile(test.SourceFile, false, false, true), test.SourceFile); Assert.AreEqual(test.ExpectedWithoutCache, ModulePath.IsPythonFile(test.SourceFile, false, true, false), test.SourceFile); var withForwards = test.SourceFile.Replace('\\', '/'); Assert.AreEqual(test.ExpectedStrict, ModulePath.IsPythonFile(withForwards, true, true, true), withForwards); Assert.AreEqual(test.ExpectedNoStrict, ModulePath.IsPythonFile(withForwards, false, true, true), withForwards); } }
private void OnChanged(object sender, FileSystemEventArgs e) { if ((Directory.Exists(e.FullPath) && !"__pycache__".Equals(PathUtils.GetFileOrDirectoryName(e.FullPath))) || ModulePath.IsPythonFile(e.FullPath, false, true, false)) { try { _refreshIsCurrentTrigger.Change(1000, Timeout.Infinite); } catch (ObjectDisposedException) { } } }
private void OnRenamed(object sender, RenamedEventArgs e) { if (Directory.Exists(e.FullPath) || ModulePath.IsPythonFile(e.FullPath, false, true, false) || ModulePath.IsPythonFile(e.OldFullPath, false, true, false)) { try { _refreshIsCurrentTrigger.Change(1000, Timeout.Infinite); } catch (ObjectDisposedException) { } } }
private async Task LoadFromDirectoryAsync(string rootDir, PatternMatchingResult matchResult) { foreach (var file in matchResult.Files) { if (_sessionTokenSource.IsCancellationRequested) { break; } var path = Path.Combine(rootDir, PathUtils.NormalizePath(file.Path)); if (!ModulePath.IsPythonSourceFile(path)) { if (ModulePath.IsPythonFile(path, true, true, true)) { // TODO: Deal with scrapable files (if we need to do anything?) } continue; } await _server.LoadFileAsync(new Uri(path)); } }
private bool ShouldDiscover(string pathToItem) { if (string.IsNullOrEmpty(pathToItem)) { return(false); } if (pathToItem.EndsWith(".pyproj", StringComparison.OrdinalIgnoreCase)) { return(true); } if (ModulePath.IsPythonFile(pathToItem)) { if (EqtTrace.IsVerboseEnabled) { EqtTrace.Verbose("TestContainerDiscoverer: Found a test {0}.", pathToItem); } return(true); } return(false); }