Ejemplo n.º 1
0
    # Render
    render_args = device, vertex_shader, fragment_shader, pipeline_layout, bind_group
    top = wgpu.PrimitiveTopology.point_list
    # render_to_screen(*render_args, topology=top)
    a = render_to_texture(*render_args, size=(64, 64), topology=top)

    # Check that the background is all zero
    bg = a.copy()
    bg[8:24, 8:24, :] = 0
    bg[8:24, 40:56, :] = 0
    bg[40:56, 8:24, :] = 0
    bg[40:56, 40:56, :] = 0
    assert np.all(bg == 0)

    # Check the square
    for dot in (
        a[8:24, 8:24, :],
        a[8:24, 40:56, :],
        a[40:56, 8:24, :],
        a[40:56, 40:56, :],
    ):
        assert np.all(dot[:, :, 0] == 255)  # red
        assert np.all(dot[:, :, 1] == 127)  # green
        assert np.all(dot[:, :, 2] == 0)  # blue
        assert np.all(dot[:, :, 3] == 255)  # alpha


if __name__ == "__main__":
    run_tests(globals())
Ejemplo n.º 2
0
        self.assertTrue(df.equals(G1_DF_R0))

        df = roundoff_df(G1_DF, 2)
        self.assertTrue(df.equals(G1_DF_R2))

        df = roundoff_df(G1_DF, 2, columns=['III', 'V'])
        G1_rounded = G1_DF.copy()
        G1_rounded.reindex(list('abcd'))  # becomes acbd for some reason
        G1_rounded['III'] = pd.Series(
            dict(list(zip(list('abcd'), [2.03, 2.12, 1.44, 2.12]))))
        G1_rounded['V'] = pd.Series(
            dict(list(zip(list('abcd'), [1.46, 1.84, 1.44, 2.08]))))
        self.assertTrue(df.equals(G1_rounded))

        df = roundoff_df(G1_DF, 2, indices=['b', 'd'])
        G1_rounded = G1_DF.copy()
        G1_rounded.loc['b'] = [1.47, 1.24, 2.12, 1.59, 1.84]
        G1_rounded.loc['d'] = [2.12, 2.01, 2.12, 1.80, 2.08]
        self.assertTrue(df.equals(G1_rounded))

        df = roundoff_df(G1_DF, 2, columns=['III', 'V'], indices=['b', 'd'])
        G1_rounded = G1_DF.copy()
        G1_rounded.loc['b', ['III', 'V']] = [2.12, 1.84]
        G1_rounded.loc['d', ['III', 'V']] = [2.12, 2.08]
        self.assertTrue(df.equals(G1_rounded))


if __name__ == '__main__':
    # ut.main()
    run_tests(TestDatautils)
Ejemplo n.º 3
0
        self.assertEqual(parse_date('09/07/2014').isoformat(), '2014-09-07')

    def test_parse_date2(self):
        """Have only month and year"""
        self.assertEqual(parse_date('2014.9').isoformat(), "2014-09-01")
        self.assertEqual(parse_date('july-2014').isoformat(), "2014-07-01")
        self.assertEqual(parse_date('july-14').isoformat(), "2014-07-01")



    def test_parse_date3(self):
        """Bad options that are expected to fail"""
        self.assertNotEqual(parse_date('8.18.2014').isoformat(),    "2014-08-18")
        self.assertNotEqual(parse_date('2012091').isoformat(),      "2012-09-01")
        self.assertNotEqual(parse_date('113-13-59').isoformat(),    "2013-13-59")
        self.assertNotEqual(parse_date('01131359').isoformat(),     "2013-13-59")
        self.assertNotEqual(parse_date('jux.14').isoformat(),       "2014-xx-14")

    def test_iso_date(self):
        self.assertTrue (iso_date('2013-05-07'))
        self.assertTrue (iso_date('2013-99-77')) # crazy but isoformat
        self.assertFalse(iso_date( 20130917   )) # not a string
        self.assertFalse(iso_date('13-09-17'  )) # < 8 chars
        self.assertFalse(iso_date('2013-09-179'))# > 8 chars
        self.assertFalse(iso_date('2013--0917')) # less than 3-tuple
        self.assertFalse(iso_date('20-13-09-7')) # more than 3-tuple

if __name__ == '__main__':
    #ut.main()   # standard way to call tests
    run_tests(TestTimeutils)
Ejemplo n.º 4
0
        df = roundoff_df(G1_DF, 2)
        self.assertTrue(df.equals(G1_DF_R2))


        df = roundoff_df(G1_DF, 2, columns=['III', 'V'])
        G1_rounded = G1_DF.copy()
        G1_rounded.reindex_axis( list('abcd') )     # becomes acbd for some reason
        G1_rounded['III'] =  pd.Series(dict(zip(list('abcd'), [2.03, 2.12, 1.44, 2.12] )))
        G1_rounded['V']   =  pd.Series(dict(zip(list('abcd'), [1.46, 1.84, 1.44, 2.08] )))
        self.assertTrue(df.equals(G1_rounded))


        df = roundoff_df(G1_DF, 2, indices=['b', 'd'])
        G1_rounded = G1_DF.copy()
        G1_rounded.ix['b'] = [1.47, 1.24, 2.12, 1.59, 1.84]
        G1_rounded.ix['d'] = [2.12, 2.01, 2.12, 1.80, 2.08]
        self.assertTrue(df.equals(G1_rounded))

        df = roundoff_df(G1_DF, 2, columns=['III', 'V'], indices=['b', 'd'])
        G1_rounded = G1_DF.copy()
        G1_rounded.ix['b', ['III', 'V']] = [2.12, 1.84]
        G1_rounded.ix['d', ['III', 'V']] = [2.12, 2.08]
        self.assertTrue(df.equals(G1_rounded))



if __name__ == '__main__':
    # ut.main()
    run_tests(TestDatautils)
Ejemplo n.º 5
0
        self.assertEqual(parse_date('09/07/2014').isoformat(), '2014-09-07')

    def test_parse_date2(self):
        """Have only month and year"""
        self.assertEqual(parse_date('2014.9').isoformat(), "2014-09-01")
        self.assertEqual(parse_date('july-2014').isoformat(), "2014-07-01")
        self.assertEqual(parse_date('july-14').isoformat(), "2014-07-01")



    def test_parse_date3(self):
        """Bad options that are expected to fail"""
        self.assertNotEqual(parse_date('8.18.2014').isoformat(),    "2014-08-18")
        self.assertNotEqual(parse_date('2012091').isoformat(),      "2012-09-01")
        self.assertNotEqual(parse_date('113-13-59').isoformat(),    "2013-13-59")
        self.assertNotEqual(parse_date('01131359').isoformat(),     "2013-13-59")
        self.assertNotEqual(parse_date('jux.14').isoformat(),       "2014-xx-14")

    def test_iso_date(self):
        self.assertTrue (iso_date('2013-05-07'))
        self.assertTrue (iso_date('2013-99-77')) # crazy but isoformat
        self.assertFalse(iso_date( 20130917   )) # not a string
        self.assertFalse(iso_date('13-09-17'  )) # < 8 chars
        self.assertFalse(iso_date('2013-09-179'))# > 8 chars
        self.assertFalse(iso_date('2013--0917')) # less than 3-tuple
        self.assertFalse(iso_date('20-13-09-7')) # more than 3-tuple

if __name__ == '__main__':
    #ut.main()   # standard way to call tests
    run_tests(TestTimeutils)