diff --git a/src/diana/__init__.py b/src/diana/__init__.py new file mode 100644 diff --git a/src/diana.py b/src/diana/diana.py rename from src/diana.py rename to src/diana/diana.py --- a/src/diana.py +++ b/src/diana/diana.py @@ -1,8 +1,9 @@ -import sys +import os import re -import go -import os -import sgf +import sys + +import diana.sgf as sgf +import diana.go as go if len(sys.argv)>1: files=sys.argv[1:] @@ -132,7 +133,7 @@ def processFile(fileName): game=go.Go() global t - record=sgf.Sgf(open(fileName,'r',encoding="utf-8").read()) + record= sgf.Sgf(open(fileName, 'r', encoding="utf-8").read()) moves=record.getMoves() localBoard=dict() diff --git a/src/go.py b/src/diana/go.py rename from src/go.py rename to src/diana/go.py diff --git a/src/sgf.py b/src/diana/sgf.py rename from src/sgf.py rename to src/diana/sgf.py --- a/src/sgf.py +++ b/src/diana/sgf.py @@ -490,9 +490,6 @@ def simpleText(str): res+=c return res""" -sgf=open("in/1-Hora-Simara.sgf").read() - -x=Collection(sgf) # TODO: # date diff --git a/src/sgfParser.py b/src/diana/sgfParser.py rename from src/sgfParser.py rename to src/diana/sgfParser.py --- a/src/sgfParser.py +++ b/src/diana/sgfParser.py @@ -1,5 +1,5 @@ import re - + def skipWhitespace(str,start): i=start while i<len(str) and str[i].isspace(): i+=1 @@ -430,10 +430,6 @@ def simpleText(str): res+=c return res""" -sgf=open("in/1-Hora-Simara.sgf").read() - -x=Collection(sgf) - # TODO: # date diff --git a/src/diana/tests/__init__.py b/src/diana/tests/__init__.py new file mode 100644 diff --git a/src/diana/tests/data/simple.sgf b/src/diana/tests/data/simple.sgf new file mode 100755 --- /dev/null +++ b/src/diana/tests/data/simple.sgf @@ -0,0 +1,39 @@ +(;SZ[19]FF[3] +PW[Kobayashi Koichi] +WR[9d] +PB[Kato Masao] +BR[9d] +EV[15th Kisei Final] +RO[Game 1] +DT[1991-01-18,19] +PC[Caesar Park Hotel, Sao Paulo] +KM[5.5] +RE[B+1.5] +US[GoGoD95] +;B[qd];W[dp];B[cd];W[qp];B[oc];W[ed];B[ec];W[fc];B[dc];W[gd];B[cf];W[kc] +;B[oq];W[lp];B[oo];W[pn];B[pl];W[on];B[mo];W[nm];B[lo];W[jp];B[kp];W[kq] +;B[ko];W[iq];B[pi];W[pq];B[lq];W[lr];B[mq];W[qg];B[hc];W[gb];B[jc];W[jd] +;B[kd];W[lc];B[je];W[id];B[hd];W[ie];B[he];W[ic];B[ib];W[if];B[hb];W[jb] +;B[hf];W[ff];B[ig];W[jf];B[gh];W[fh];B[fi];W[gg];B[hg];W[gi];B[hh];W[eh] +;B[fj];W[di];B[dj];W[cj];B[ck];W[dk];B[ej];W[ci];B[cl];W[dg];B[fp];W[cn] +;B[em];W[eb];B[db];W[dm];B[dl];W[en];B[hp];W[fm];B[el];W[gn];B[fo];W[fn] +;B[jo];W[ip];B[ho];W[hj];B[hk];W[ik];B[hl];W[il];B[hm];W[hn];B[io];W[jj] +;B[gj];W[hi];B[kh];W[im];B[fl];W[da];B[ca];W[ea];B[ga];W[fb];B[ee];W[de] +;B[dd];W[fd];B[df];W[ef];B[bb];W[oi];B[mi];W[lh];B[ki];W[lk];B[lg];W[oh] +;B[nl];W[ok];B[ol];W[mj];B[md];W[mf];B[ng];W[mg];B[mh];W[lf];B[nh];W[nf] +;B[og];W[ph];B[nj];W[nk];B[ml];W[mk];B[of];W[kg];B[li];W[pj];B[rf];W[qf] +;B[qe];W[mm];B[in];W[dr];B[ll];W[lm];B[kl];W[km];B[kk];W[kj];B[lj];W[jl] +;B[rj];W[ri];B[qm];W[qk];B[rk];W[qj];B[ql];W[sj];B[rl];W[rg];B[rn];W[po] +;B[sm];W[rp];B[ro];W[jr];B[hr];W[ir];B[ls];W[ms];B[mr];W[ks];B[ns];W[nr] +;B[ls];W[jg];B[jh];W[ms];B[nn];W[om];B[ls];W[ii];B[ih];W[ms];B[cp];W[co] +;B[ls];W[so];B[sk];W[ms];B[jm];W[jn];B[ls];W[gl];B[gk];W[ms];B[do];W[cq] +;B[ls];W[nd];B[pr];W[qr];B[op];W[pp];B[ne];W[or];B[me];W[nb];B[ob];W[ld] +;B[kr];W[nc];B[od];W[lr];B[bg];W[ch];B[kr];W[gr];B[hq];W[lr];B[nq];W[ms] +;B[os];W[rr];B[ls];W[is];B[kr];W[hs];B[fr];W[lr];B[ji];W[ij];B[kr];W[fs] +;B[es];W[er];B[gs];W[lr];B[fs];W[kr];B[mc];W[mb];B[re];W[le];B[oe];W[bm] +;B[bl];W[eo];B[ni];W[qi];B[si];W[sg];B[eq];W[dq];B[bh];W[bi];B[cm];W[an] +;B[gm];W[fe];B[cg];W[ei];B[ds];W[cs];B[fq];W[lb];B[na];W[ma];B[oa];W[dn] +;B[gf];W[fg];B[sf];W[ce];B[be];W[ee];B[ah];W[mn];B[no];W[pf];B[pe];W[go] +;B[gp];W[qs];B[al];W[ps];B[am];W[bn];B[ep];W[br];B[or];W[sh];B[ja];W[ka] +;B[ia];W[lg];B[sj];W[ms] +) diff --git a/src/diana/tests/sgfParser.py b/src/diana/tests/sgfParser.py new file mode 100644 --- /dev/null +++ b/src/diana/tests/sgfParser.py @@ -0,0 +1,19 @@ +import unittest +from unittest import TestCase +import os + +from ..sgfParser import Collection + + +dataDir=os.path.join(os.path.dirname(__file__), "data") + +class TestCollection(TestCase): + def testEmptySgf(self): + Collection("(;)") + + def testSimpleSgf(self): + with open(os.path.join(dataDir, "simple.sgf")) as f: + Collection(f.read()) + +if __name__ == '__main__': + unittest.main()