示例#1
0
class test_GalIO(unittest.TestCase):
    def setUp(self):
        self.test_file = test_file = pysal.examples.get_path('sids2.gal')
        self.obj = GalIO(test_file, 'r')

    def test___init__(self):
        self.assertEqual(self.obj._typ, str)

    def test_close(self):
        f = self.obj
        f.close()
        self.assertRaises(ValueError, f.read)

    def test_read(self):
        # reading a GAL returns a W
        w = self.obj.read()
        self.assertEqual(w.n, 100)
        self.assertAlmostEqual(w.sd, 1.5151237573214935)
        self.assertEqual(w.s0, 462.0)
        self.assertEqual(w.s1, 924.0)

    def test_seek(self):
        self.test_read()
        self.assertRaises(StopIteration, self.obj.read)
        self.obj.seek(0)
        self.test_read()

    def test_write(self):
        w = self.obj.read()
        f = tempfile.NamedTemporaryFile(suffix='.gal')
        fname = f.name
        f.close()
        o = pysal.open(fname, 'w')
        o.write(w)
        o.close()
        wnew = pysal.open(fname, 'r').read()
        self.assertEqual(wnew.pct_nonzero, w.pct_nonzero)
示例#2
0
文件: test_gal.py 项目: CartoDB/pysal
class test_GalIO(unittest.TestCase):
    def setUp(self):
        self.test_file = test_file = pysal.examples.get_path('sids2.gal')
        self.obj = GalIO(test_file, 'r')

    def test___init__(self):
        self.assertEqual(self.obj._typ, str)

    def test_close(self):
        f = self.obj
        f.close()
        self.failUnlessRaises(ValueError, f.read)

    def test_read(self):
        # reading a GAL returns a W
        w = self.obj.read()
        self.assertEqual(w.n, 100)
        self.assertAlmostEqual(w.sd, 1.5151237573214935)
        self.assertEqual(w.s0, 462.0)
        self.assertEqual(w.s1, 924.0)

    def test_seek(self):
        self.test_read()
        self.failUnlessRaises(StopIteration, self.obj.read)
        self.obj.seek(0)
        self.test_read()

    def test_write(self):
        w = self.obj.read()
        f = tempfile.NamedTemporaryFile(suffix='.gal')
        fname = f.name
        f.close()
        o = pysal.open(fname, 'w')
        o.write(w)
        o.close()
        wnew = pysal.open(fname, 'r').read()
        self.assertEqual(wnew.pct_nonzero, w.pct_nonzero)
示例#3
0
def download_w(request):
    userid = request.user.username
    if not userid:
        return HttpResponseRedirect(settings.URL_PREFIX+'/myapp/login/') 
    if request.method == 'GET':
        w_uuid = request.GET.get("w_name", None)
        w_type = request.GET.get("w_type", None)
        if w_uuid and w_type:
            response = HttpResponse(content_type='text/txt')
            response['Content-Disposition'] = 'attachment; filename="download.%s"' % w_type
            w = helper_get_W(w_uuid)
            tmp_fname = settings.MEDIA_ROOT + "/temp/w.txt" 
            if w_type == "gal":
                g = GAL(tmp_fname, "w")
            else:
                g = GWT(tmp_fname, "w")
            g.file.close()
            g.file = response
            g.write(w)
            g.close()
            return response
    return HttpResponse(RSP_FAIL, content_type="application/json")
示例#4
0
 def setUp(self):
     self.test_file = test_file = pysal.examples.get_path('sids2.gal')
     self.obj = GalIO(test_file, 'r')
示例#5
0
文件: test_gal.py 项目: CartoDB/pysal
 def setUp(self):
     self.test_file = test_file = pysal.examples.get_path('sids2.gal')
     self.obj = GalIO(test_file, 'r')