<commit_before>import java
import unittest
import simplejson as json 
from geoscript import geom, proj, feature

class Feature_Test:

  def testSchemaBasic(self):
    atts = [('att1',str),('att2',int),('geom',geom.Point)]
    s = feature.Schema('test',atts)

    assert 'test' == s.name
    n = 0
    for att in s.fields:    
      assert atts[n][0] == att.name
      assert atts[n][1] == att.typ
      n = n+1 

    assert len(atts) == n
    assert atts[2][0] == s.geom.name
    assert atts[2][1] == s.geom.typ

  def testSchemaGeomProj(self):
    prj = proj.Projection('epsg:3005')
    s = feature.Schema('test',[('att1',str),('att2',int),('geom', geom.Point,'epsg:3005')])
    assert s.geom.proj
    assert prj == s.geom.proj

  def testSchemaReproject(self):
    prj1 = proj.Projection('epsg:4326')
    prj2 = proj.Projection('epsg:3005')

    s = feature.Schema('test',[('geom', geom.Point,'epsg:4326')])
    assert s.fields[0].proj == prj1

    s = s.reproject(prj2, 'reprojected')
    assert 'reprojected' == s.name
    assert s.fields[0].proj == prj2

  def testSchemaAsContainer(self):
    s = feature.Schema('test',[('att1',str),('att2',int),('geom', geom.Point,'epsg:3005')])
    assert s['att1'] 
    assert s['att1'].typ == str

    expected = [f.name for f in s.fields]
    assert [name for name in s] == expected

    expected = [f for f in s.fields]
    print expected
    print [f for name, f in s.iteritems()]
    assert [f for name, f in s.iteritems()] == expected

    try:
      s['foo']
      assert False
    except KeyError:
      pass

    assert s.values() == s.fields 
    assert s.keys() == [f.name for f in s.fields]

  def testSchemaEquals(self):
    s1 = feature.Schema('test',[('att1',str),('att2',int),('geom', geom.Point,'epsg:3005')])
    s2 = feature.Schema('test',[('att1',str),('att2',int),('geom', geom.Point,'epsg:3005')])
    assert s1 == s2

  def testBasic(self):
    id = 'fid'
    g = geom.Point(-125, 50)
    a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
    f = feature.Feature(a,'fid')
    assert id == f.id
    assert g == f.geom

  def testAsContainer(self):
    id = 'fid'
    g = geom.Point(-125, 50)
    a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
    f = feature.Feature(a,'fid')

    assert 1 == f['x']
    try:
      f['foo'] 
      assert False
    except KeyError:
      pass

    assert [x for x in f.schema] == [y for y in f]
    expected = [(x,y) for x,y in f.attributes.iteritems()]
    assert [(x,y) for x,y in f.iteritems()] == expected
   
    assert f.attributes.keys() == f.keys()
    assert f.attributes.values() == f.values()

  def testEquals(self):
    id = 'fid'
    g = geom.Point(-125, 50)
    a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
    f1 = feature.Feature(a,'fid')
    f2 = feature.Feature(a,'fid')
    assert f1 == f2

  def testBounds(self):
    g = geom.LineString((1,1), (10,10))
    f = feature.Feature({'geom': g}, 'fid')
   
    assert 1 == f.bounds.west 
    assert 1 == f.bounds.south 
    assert 10 == f.bounds.east
    assert 10 == f.bounds.north

  def testBoundsNoGeom(self):
    f = feature.Feature({'x': 1}, 'fid')
    assert None == f.bounds

  def testWriteJSON(self):
    g = geom.Point(-125, 50)
    a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}<commit_msg>not relying on dictionary sorting order<commit_after>import java
import unittest
import simplejson as json 
from geoscript import geom, proj, feature

class Feature_Test:

  def testSchemaBasic(self):
    atts = [('att1',str),('att2',int),('geom',geom.Point)]
    s = feature.Schema('test',atts)

    assert 'test' == s.name
    n = 0
    for att in s.fields:    
      assert atts[n][0] == att.name
      assert atts[n][1] == att.typ
      n = n+1 

    assert len(atts) == n
    assert atts[2][0] == s.geom.name
    assert atts[2][1] == s.geom.typ

  def testSchemaGeomProj(self):
    prj = proj.Projection('epsg:3005')
    s = feature.Schema('test',[('att1',str),('att2',int),('geom', geom.Point,'epsg:3005')])
    assert s.geom.proj
    assert prj == s.geom.proj

  def testSchemaReproject(self):
    prj1 = proj.Projection('epsg:4326')
    prj2 = proj.Projection('epsg:3005')

    s = feature.Schema('test',[('geom', geom.Point,'epsg:4326')])
    assert s.fields[0].proj == prj1

    s = s.reproject(prj2, 'reprojected')
    assert 'reprojected' == s.name
    assert s.fields[0].proj == prj2

  def testSchemaAsContainer(self):
    s = feature.Schema('test',[('att1',str),('att2',int),('geom', geom.Point,'epsg:3005')])
    assert s['att1'] 
    assert s['att1'].typ == str

    expected = [f.name for f in s.fields]
    assert [name for name in s] == expected

    expected = [f for f in s.fields]
    print expected
    print [f for name, f in s.iteritems()]
    assert [f for name, f in s.iteritems()] == expected

    try:
      s['foo']
      assert False
    except KeyError:
      pass

    assert s.values() == s.fields 
    assert s.keys() == [f.name for f in s.fields]

  def testSchemaEquals(self):
    s1 = feature.Schema('test',[('att1',str),('att2',int),('geom', geom.Point,'epsg:3005')])
    s2 = feature.Schema('test',[('att1',str),('att2',int),('geom', geom.Point,'epsg:3005')])
    assert s1 == s2

  def testBasic(self):
    id = 'fid'
    g = geom.Point(-125, 50)
    a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
    f = feature.Feature(a,'fid')
    assert id == f.id
    assert g == f.geom

  def testAsContainer(self):
    id = 'fid'
    g = geom.Point(-125, 50)
    a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
    f = feature.Feature(a,'fid')

    assert 1 == f['x']
    try:
      f['foo'] 
      assert False
    except KeyError:
      pass

    assert [x for x in f.schema] == [y for y in f]
    expected = [(x,y) for x,y in f.attributes.iteritems()]
    assert [(x,y) for x,y in f.iteritems()] == expected
   
    assert sorted(f.attributes.keys()) == sorted(f.keys())
    assert sorted(f.attributes.values()) == sorted(f.values())

  def testEquals(self):
    id = 'fid'
    g = geom.Point(-125, 50)
    a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
    f1 = feature.Feature(a,'fid')
    f2 = feature.Feature(a,'fid')
    assert f1 == f2

  def testBounds(self):
    g = geom.LineString((1,1), (10,10))
    f = feature.Feature({'geom': g}, 'fid')
   
    assert 1 == f.bounds.west 
    assert 1 == f.bounds.south 
    assert 10 == f.bounds.east
    assert 10 == f.bounds.north

  def testBoundsNoGeom(self):
    f = feature.Feature({'x': 1}, 'fid')
    assert None == f.bounds

  def testWriteJSON(self):
    g = geom.Point(-125, 50)
    a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
{'fraction_non_alphanumeric': 0.19331306990881458, 'fraction_numerical': 0.03434650455927052, 'mean_word_length': 2.8894799054373523, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3180633', 'n_tokens_mistral': 2696, 'n_tokens_neox': 2504, 'n_words': 612}