These are chat archives for pybee/general

4th
Jan 2017
Sanjeev
@Sanjeev-S
Jan 04 2017 00:22

Again just for clarity before I work.

Suppose I choose a not implemented test 'test_modulo_bool' from test_str. Then I have to modify "public org.python.Object mod(org.python.Object other)" function from Str.java, right? So that the other object is of type bool.

Also where is the actual test implemented, so that if we do it correctly, it results in an unexpected success?

Russell Keith-Magee
@freakboy3742
Jan 04 2017 00:27
@Sanjeev-S Correct - that’s the right place to make the change.
The test is automatically generated. tests/utils.py contains the testing base class; it takes a collection of sample data (sample integers, strings, bools) and pairs them with the chosen operator (%) and compares the result under CPython to the result under VOC.
The output you get in the case of an unexpected error is the diff between CPython output and VOC output for the same code.
Sanjeev
@Sanjeev-S
Jan 04 2017 00:35
Thank you :)
Sanjeev
@Sanjeev-S
Jan 04 2017 03:16

Do we need to install virutal env create each time you open a new terminal?

$ virtualenv -p $(which python3) env
$ . env/bin/activate
$ cd voc
$ pip install -e .

Or can we open the previously created env?

Russell Keith-Magee
@freakboy3742
Jan 04 2017 03:17
You don’t need to create a new environment, but you do need to activate it.
Sanjeev
@Sanjeev-S
Jan 04 2017 03:17
So just do till line 2?
Russell Keith-Magee
@freakboy3742
Jan 04 2017 03:18
Correct.
Sanjeev
@Sanjeev-S
Jan 04 2017 03:18
:)
Russell Keith-Magee
@freakboy3742
Jan 04 2017 03:18
Wait - Do line 2 and 3; you don’t need to do 1 and 4
Sanjeev
@Sanjeev-S
Jan 04 2017 03:20
Alright :)
Sanjeev
@Sanjeev-S
Jan 04 2017 07:34
I was trying to do multiply string by class. (test_multiply_class). "<class 'TypeError'> : can't multiply sequence by non-int of type 'type'" should be the output in all cases.

But I am getting errors like "<class 'NotImplementedError'> : 3-argument form of builtin function 'type' not implemented".

Can it be solved by just modifying the "public org.python.Object mul(org.python.Object other)" function or is there any non local corrections also to be made?

Russell Keith-Magee
@freakboy3742
Jan 04 2017 07:37
Ok - the tests involving class are a bit broken at the moment - because dynamically creating a class in Java is a bit tricky.
Essentially type() needs to be able to return an entirely new Class - which is difficult to do in the context of the JVM.
Sanjeev
@Sanjeev-S
Jan 04 2017 12:56

I made some changes to the implementation of mod for bool but when I run test case I'm getting it as an expected failure:

test_modulo_bool
(tests.datatypes.test_str.BinaryStrOperationTests) ... expected failure

----------------------------------------------------------------------
Ran 1 test in 3.425s

OK (expected failures=1)

But if I comment out 'test_modulo_bool' in test_str.py I am getting

'test_modulo_bool'
test_modulo_bool (tests.datatypes.test_str.BinaryStrOperationTests) ... ok

----------------------------------------------------------------------
Ran 1 test in 3.882s

OK

How do I get the result as unexpected success? (I still have a little more to do in modulo bool but I just wanted to see it coming as unexpected success by reverse engineering the sample data)

Russell Keith-Magee
@freakboy3742
Jan 04 2017 13:00
That's... odd. Are you sure you commented out the Binary test version? There's an Inplace test in the same file.
Sanjeev
@Sanjeev-S
Jan 04 2017 13:02
Nope, I just commented out from class BinaryStrOperationTests. I'll try commenting out the other too.
Russell Keith-Magee
@freakboy3742
Jan 04 2017 13:03
The output you're seeing would be consistent with running a different test to the one you uncommented.
Sanjeev
@Sanjeev-S
Jan 04 2017 13:04
Oh, I see your point now. Let me check.

No, I commented out the right one. Line no. 300.

This is the output after commenting out

test_modulo_bool (tests.datatypes.test_str.BinaryStrOperationTests) ... ok

----------------------------------------------------------------------
Ran 1 test in 3.787s

OK
The input was python setup.py test -s tests.datatypes.test_str.BinaryStrOperationTests.test_modulo_bool
And before commenting out it shows, expected failure.
Sanjeev
@Sanjeev-S
Jan 04 2017 13:10

This is basically the changes I made in the mod function.

 else if(other instanceof org.python.types.Bool) {
              boolean other_bool = ((org.python.types.Bool)other).value;
              java.lang.String res;
              if(value.indexOf("%s") >=0 && value.indexOf("%s")==value.lastIndexOf("%s")) {
                  if(other_bool) {
                      res= value.substring(0, value.indexOf("%s"))+"True"+value.substring((value.indexOf("%s")+2));
                  } else {
                      res= value.substring(0, value.indexOf("%s"))+"False"+value.substring((value.indexOf("%s")+2));
                  }
                  //System.out.println("TEST "+res);
                  return new Str(res);
              } else if(value.indexOf("%s") >=0 && value.indexOf("%s")!=value.lastIndexOf("%s")) {
                  throw new org.python.exceptions.TypeError("not enough arguments for format string");
              } else {
                    throw new org.python.exceptions.TypeError("not all arguments converted during string formatting");     
                } 
}

I know it is not the general case but it works for test input. And I just wanted to see if it would come unexpected success.

Russell Keith-Magee
@freakboy3742
Jan 04 2017 14:00
Hang about - if you’ve made a change to Str.java and uncommented test_modulo_bool, it’s entirely possible you’ve made it work.
Can you stash/revert your changes to Str.java and confirm you get a failure?
Sanjeev
@Sanjeev-S
Jan 04 2017 16:03

Oh alright. I think I understand now. Even my guess was I made it work.
I was expecting receiving some sort of "unexpected success" message. Hence the confusion.

I will just re-iterate to see if I understand correctly.

  1. Uncomment test_modulo_bool or any other test.
  2. The build fails.(saying failed showing stack trace)
  3. Make changes to Str.java until build passes.
  4. The build passing(saying OK) means I successfully implemented the function.

(I didn't do step 1 and was expecting "unexpected success" message)

PS. I'd also love to make some changes to documentation. Trivial changes mostly, but maybe helpful to the less experienced people. :)
(A lot out of my interaction with you)
Russell Keith-Magee
@freakboy3742
Jan 04 2017 23:56
@Sanjeev-S That’s it exactly. And yes - if you want to suggest fixes to make things clearer for new contributors (be they first time contributors or experienced contributors new to BeeWare), any suggestions are welcome.