<commit_before>
(use-modules (opencog) )
(use-modules (opencog test-runner))
(use-modules (opencog python))

(opencog-test-runner)
(define t "opencog-arity-test")

(test-begin t)

(python-eval "
from opencog.atomspace import AtomSpace, TruthValue
from opencog.atomspace import types
def foo(atspace):
    TV = TruthValue(0.2, 0.69)
    atspace.add_node(types.ConceptNode, 'Apple', TV)
")

(python-call-with-as "foo" (cog-atomspace))
(test-assert "atom was created" (not (eq? #f (cog-node 'ConceptNode "Apple"))))

(define strength (cog-mean (cog-node 'ConceptNode "Apple")))

(test-assert "strength value is wrong" (< (- 0.2 strength) 0.00001))


(define (catch-wrong-args thunk)
  (catch #t 
    thunk
    (lambda (key . parameters)
      (format (current-error-port)
              "caught throw to '~a: ~a\n" key parameters)
      "catch")))

(define failed-result
  (catch-wrong-args
   (lambda () (python-call-with-as "foo" (cog-atomspace) (cog-new-node 'ConceptNode "Test")))))

(test-assert "no error with wrong number of arguments" (string=? failed-result "catch"))
(test-end t)<commit_msg>Cleanup related to pull req #2012<commit_after>
(use-modules (opencog))
(use-modules (opencog test-runner))
(use-modules (opencog python))

(opencog-test-runner)

(define tname "opencog-arity-test")
(test-begin tname)

(python-eval "
from opencog.atomspace import AtomSpace, TruthValue
from opencog.atomspace import types
def foo(atspace):
    TV = TruthValue(0.2, 0.69)
    atspace.add_node(types.ConceptNode, 'Apple', TV)
")

(python-call-with-as "foo" (cog-atomspace))
(test-assert "atom was created" (not (eq? #f (cog-node 'ConceptNode "Apple"))))

; Make sure the scheme version of Apple has the same TV on it that
; the python code placed on it.
(define strength (cog-mean (Concept "Apple")))
(test-assert "strength value is wrong" (< (abs (- 0.2 strength)) 0.00001))

(define (catch-wrong-args thunk)
  (catch #t 
    thunk
    (lambda (key . parameters)
      (format (current-error-port)
         "Expected to catch this Python exception: '~a: ~a\n" key parameters)
      "woo-hooo!!")))

(define failed-result
  (catch-wrong-args
    (lambda () (python-call-with-as "foo" (cog-atomspace) (Concept "Test")))))

(test-assert "Failed to throw when given wrong number of arguments"
	(string=? failed-result "woo-hooo!!"))

(test-end tname)
{'fraction_non_alphanumeric': 0.15713065755764305, 'fraction_numerical': 0.012809564474807857, 'mean_word_length': 4.12691466083151, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2618743', 'n_tokens_mistral': 877, 'n_tokens_neox': 839, 'n_words': 232}