<commit_before>(ns clojars.test-helper
  (:require [clojars
             [cloudfiles :as cf]
             [config :refer [config]]
             [errors :as errors]
             [stats :as stats]
             [search :as search]
             [system :as system]
             [web :as web]]
            [clojars.db.migrate :as migrate]
            [clojars.storage :as storage]
            [clojure.java
             [io :as io]
             [jdbc :as jdbc]]
            [clojure.string :as str]
            [clucy.core :as clucy]
            [com.stuartsierra.component :as component])
  (:import java.io.File))

(def tmp-dir (io/file (System/getProperty "java.io.tmpdir")))
(def local-repo (io/file tmp-dir "clojars" "test" "local-repo"))
(def local-repo2 (io/file tmp-dir "clojars" "test" "local-repo2"))

(def test-config {:port 0
                  :db {:dbtype "postgresql"
                       :dbname "clojars"
                       :host "localhost"
                       :port 55432
                       :user "clojars"
                       :password "<PASSWORD>"}
                  :repo "data/test/repo"
                  :deletion-backup-dir "data/test/repo-backup"})

(defn using-test-config [f]
  (let [orig-config @config]
    (with-redefs [config (delay (merge orig-config test-config))]
      (f))))

(defn delete-file-recursively
  "Delete file f. If it's a directory, recursively delete all its contents."
  [f]
  (let [f (io/file f)]
    (when (.exists f)
      (when (.isDirectory f)
        (doseq [child (.listFiles f)]
          (delete-file-recursively child)))
      (io/delete-file f))))

(defn default-fixture [f]
  (using-test-config
    (let [cleanup (fn [] (run!
                          #(delete-file-recursively (io/file (@config %)))
                          [:deletion-backup-dir :repo]))]
      (fn []
        (cleanup)
        (f)
        (cleanup)))))

(defn quiet-reporter []
  (reify errors/ErrorReporter
    (-report-error [t e ex id]
      (println t e ex id))))

(declare ^:dynamic *db*)

(defn clear-database [db]
  (jdbc/db-do-commands db
                       "delete from deps"
                       "delete from groups"
                       "delete from jars"
                       "delete from users"))
<commit_msg>Don't throw if tables to clear don't exist<commit_after>(ns clojars.test-helper
  (:require [clojars
             [cloudfiles :as cf]
             [config :refer [config]]
             [errors :as errors]
             [stats :as stats]
             [search :as search]
             [system :as system]
             [web :as web]]
            [clojars.db.migrate :as migrate]
            [clojars.storage :as storage]
            [clojure.java
             [io :as io]
             [jdbc :as jdbc]]
            [clojure.string :as str]
            [clucy.core :as clucy]
            [com.stuartsierra.component :as component])
  (:import java.io.File))

(def tmp-dir (io/file (System/getProperty "java.io.tmpdir")))
(def local-repo (io/file tmp-dir "clojars" "test" "local-repo"))
(def local-repo2 (io/file tmp-dir "clojars" "test" "local-repo2"))

(def test-config {:port 0
                  :db {:dbtype "postgresql"
                       :dbname "clojars"
                       :host "localhost"
                       :port 55433
                       :user "clojars"
                       :password "<PASSWORD>"}
                  :repo "data/test/repo"
                  :deletion-backup-dir "data/test/repo-backup"})

(defn using-test-config [f]
  (let [orig-config @config]
    (with-redefs [config (delay (merge orig-config test-config))]
      (f))))

(defn delete-file-recursively
  "Delete file f. If it's a directory, recursively delete all its contents."
  [f]
  (let [f (io/file f)]
    (when (.exists f)
      (when (.isDirectory f)
        (doseq [child (.listFiles f)]
          (delete-file-recursively child)))
      (io/delete-file f))))

(defn default-fixture [f]
  (using-test-config
    (let [cleanup (fn [] (run!
                          #(delete-file-recursively (io/file (@config %)))
                          [:deletion-backup-dir :repo]))]
      (fn []
        (cleanup)
        (f)
        (cleanup)))))

(defn quiet-reporter []
  (reify errors/ErrorReporter
    (-report-error [t e ex id]
      (println t e ex id))))

(declare ^:dynamic *db*)

(defn clear-database [db]
  (try
    (jdbc/db-do-commands db
                         "delete from deps"
                         "delete from groups"
                         "delete from jars"
                         "delete from users")
    (catch Exception _)))

{'fraction_non_alphanumeric': 0.1349189189189189, 'fraction_numerical': 0.0034594594594594594, 'mean_word_length': 1.6076662908680948, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6060597', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1410, 'n_words': 382}