Skip to content

Commit e1f699e

Browse files
committed
Made Demo 25 python 3 compatible.
1 parent cde4e72 commit e1f699e

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

Demos/Demo25/fmMain.pas

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,11 @@ procedure TMain.btnTestSequencesClick(Sender: TObject);
585585
Assert(String(b) = '[4, 5, 6]');
586586
// now with a literal: note that with D6 SP1, we can't concatenate a custom variant with a var array of variants
587587
c := a + b + VarPythonCreate(['Hello', 'World!', 3.14]);
588-
Assert( String(c) = '[1, 2, 3, 4, 5, 6, u''Hello'', u''World!'', 3.1400000000000001]' );
588+
Assert( String(c) = '[1, 2, 3, 4, 5, 6, ''Hello'', ''World!'', 3.14]' );
589589
c := a + VarPythonCreate(['Hello', 'World!', 3.14]) + b;
590-
Assert( String(c) = '[1, 2, 3, u''Hello'', u''World!'', 3.1400000000000001, 4, 5, 6]' );
590+
Assert( String(c) = '[1, 2, 3, ''Hello'', ''World!'', 3.14, 4, 5, 6]' );
591591
c := VarPythonCreate(['Hello', 'World!', 3.14]) + a + b;
592-
Assert( String(c) = '[u''Hello'', u''World!'', 3.1400000000000001, 1, 2, 3, 4, 5, 6]' );
592+
Assert( String(c) = '[''Hello'', ''World!'', 3.14, 1, 2, 3, 4, 5, 6]' );
593593

594594
// multiplication
595595
c := a * 3; // in Python the multiplication of sequence concatenates n times the sequence
@@ -687,17 +687,16 @@ procedure TMain.btnTestSequencesClick(Sender: TObject);
687687
Assert( VarIsPythonSequence(c) );
688688
Assert( c.GetItem(1) = 2 );
689689
Assert( c.Length = 3 );
690-
Assert(not VarIsPythonIterator(c));
691690

692691
// test iterator
693692
iter := BuiltinModule.iter(VarPythonCreate([1, 2, 3, 4], stTuple));
694693
Assert(VarIsPythonIterator(iter));
695-
Assert(iter.next() = 1);
696-
Assert(iter.next() = 2);
697-
Assert(iter.next() = 3);
698-
Assert(iter.next() = 4);
694+
Assert(iter.__next__() = 1);
695+
Assert(iter.__next__() = 2);
696+
Assert(iter.__next__() = 3);
697+
Assert(iter.__next__() = 4);
699698
try
700-
iter.next();
699+
iter.__next__();
701700
except
702701
on E: EPyStopIteration do
703702
begin
@@ -712,7 +711,7 @@ procedure TMain.btnTestSequencesClick(Sender: TObject);
712711
try
713712
while True do
714713
begin
715-
a := iter.next();
714+
a := iter.__next__();
716715
Inc(cpt);
717716
Assert(a = cpt);
718717
end;
@@ -772,10 +771,10 @@ procedure TMain.btnTestMappingsClick(Sender: TObject);
772771
// dict methods
773772
Assert( Boolean(a.get(string('a'))) );
774773
Assert( not Boolean(a.get('abc')) );
775-
keys := a.keys();
774+
keys := BuiltinModule.list(a.keys());
776775
keys.sort();
777776
Assert( keys = VarPythonCreate(VarArrayOf(['a', 'b', 'c'])));
778-
values := a.values();
777+
values := BuiltinModule.list(a.values());
779778
values.sort();
780779
Assert( values = VarPythonCreate(VarArrayOf([1, 2, 3])));
781780
c := a;
@@ -999,7 +998,6 @@ procedure TMain.btnTestObjectsClick(Sender: TObject);
999998
Assert( VarIsPythonCallable(_main.Foo) );
1000999
Assert( VarIsPythonCallable(_main.Foo) );
10011000
Assert( VarIsTrue(BuiltinModule.callable(_main.Foo)) );
1002-
Assert( VarIsPythonInstance(_main.f) );
10031001
Assert( VarIsSame(_main.f.__class__, _main.Foo) );
10041002
Assert( VarIsPythonMethod(_main.f.Inc) );
10051003
Assert( VarIsPythonCallable(_main.f.Inc) );
@@ -1119,7 +1117,7 @@ procedure TMain.btnTestObjectsClick(Sender: TObject);
11191117
Assert( _myModule.Add(2, 2) = 4 );
11201118
// delete module var f
11211119
_main.__dict__.DeleteItem(string('f'));
1122-
Assert( _main.__dict__.get(string('f')) = False );
1120+
Assert(VarIsNone(_main.__dict__.get(string('f'))));
11231121
// open a file using Python
11241122
if FileExists('MyModule.py') then
11251123
begin

0 commit comments

Comments
 (0)