Example #1
0
 def test_unique(self):
     """ Graphs must have unique names in an Environment """
     env = pike.Environment()
     with pike.Graph('g') as graph:
         pike.glob('.', '*')
     env.add(graph)
     with self.assertRaises(KeyError):
         env.add(graph)
Example #2
0
 def test_lookup_missing(self):
     """ Lookup if missing returns None """
     env = pike.Environment()
     with pike.Graph('g') as graph:
         pike.glob('.', '*')
     env.add(graph)
     env.run_all()
     ret = env.lookup('foo')
     self.assertIsNone(ret)
Example #3
0
 def test_no_change(self):
     """ If no files change, return no files """
     with pike.Graph('g') as graph:
         pike.glob('.', '*') | pike.ChangeListenerNode(stop=False)
     self.make_files('foo')
     ret = graph.run()
     self.assert_files_equal(ret['default'], ['foo'])
     ret = graph.run()
     self.assert_files_equal(ret['default'], [])
Example #4
0
def main():
    """ Run graph forever """
    env = pike.Environment(watch=True, cache='.pike-cache')
    with pike.Graph('docs') as graph:
        builder = DocBuilderNode()
        pike.glob('doc', '*.rst') | builder
        pike.glob('pike', '*.py') | builder
    env.add(graph)
    env.run_forever(sleep=1)
Example #5
0
 def test_watch_graph_caches(self):
     """ Watching a graph will raise StopProcessing if no file changes """
     self.make_files(foo='foo', bar='bar')
     with pike.Graph('g') as graph:
         pike.glob('.', '*')
     watcher = pike.watch_graph(graph)
     ret = watcher.run()
     self.assertEqual(len(ret['default']), 2)
     with self.assertRaises(pike.StopProcessing):
         watcher.run()
Example #6
0
 def test_change_data(self):
     """ If file data changes, it is passed on """
     with pike.Graph('g') as graph:
         pike.glob('.', '*') | pike.ChangeListenerNode()
     self.make_files(foo='a', bar='b')
     ret = graph.run()
     self.assert_files_equal(ret['default'], ['foo', 'bar'])
     self.make_files(foo='asdf', bar='b')
     ret = graph.run()
     self.assert_files_equal(ret['default'], ['foo'])
Example #7
0
 def test_lookup(self):
     """ Lookup returns full file path """
     env = pike.Environment()
     self.make_files('foo')
     with pike.Graph('g') as graph:
         pike.glob('.', '*')
     env.add(graph)
     env.run_all()
     ret = env.lookup('foo')
     self.assertEqual(ret, os.path.join('.', 'foo'))
Example #8
0
 def test_clean(self):
     """ Cleaning directory should delete unknown files """
     self.make_files('foo.py', 'bar.js')
     env = pike.Environment()
     with pike.Graph('g') as graph:
         pike.glob('.', '*.py')
     env.add(graph)
     env.run_all()
     env.clean('.')
     self.assertTrue(os.path.exists('foo.py'))
     self.assertFalse(os.path.exists('bar.js'))
Example #9
0
 def test_change_mtime(self):
     """ If watching mtime, update on mtime change """
     with pike.Graph('g') as graph:
         pike.glob('.', '*') | pike.ChangeListenerNode(fingerprint='mtime')
     self.make_files(foo='a', bar='b')
     ret = graph.run()
     self.assert_files_equal(ret['default'], ['foo', 'bar'])
     new_mtime = time.time() + 1
     os.utime('foo', (new_mtime, new_mtime))
     ret = graph.run()
     self.assert_files_equal(ret['default'], ['foo'])
Example #10
0
 def test_clean_dry_run(self):
     """ A dry run will mark files for deletion but leave them on disk """
     self.make_files('foo.py', 'bar.js')
     env = pike.Environment()
     with pike.Graph('g') as graph:
         pike.glob('.', '*.py')
     env.add(graph)
     env.run_all()
     removed = env.clean('.', dry_run=True)
     self.assertEqual(removed, [os.path.abspath('bar.js')])
     self.assertTrue(os.path.exists('foo.py'))
     self.assertTrue(os.path.exists('bar.js'))
Example #11
0
 def test_default_output(self):
     """ Default output is auto appended to all graphs """
     env = pike.Environment()
     output = pike.Graph('output')
     output.sink = pike.noop()
     with patch.object(output, 'run') as run:
         run.return_value = []
         env.set_default_output(output)
         with pike.Graph('g') as graph:
             pike.glob('.', '*')
         env.add(graph)
         env.run_all()
         run.assert_called_with([])
Example #12
0
 def test_watch_graph_partial_changes(self):
     """ Watching a graph with partial runs will return new files """
     self.make_files(foo='foo', bar='bar')
     with pike.Graph('g') as graph:
         pike.glob('.', '*')
     watcher = pike.watch_graph(graph, partial=True)
     ret = watcher.run()
     self.assertItemsEqual([f.data.read() for f in ret['default']],
                           [b'foo', b'bar'])
     self.make_files(foo='foo', bar='foo')
     ret = watcher.run()
     self.assertItemsEqual([f.data.read() for f in ret['default']],
                           [b'foo', b'foo'])
Example #13
0
def main():
    """ Run graph forever """
    logging.basicConfig()
    parser = argparse.ArgumentParser(description=main.__doc__)
    parser.add_argument('-c', '--coverage', action='store_true',
                        help="Collect coverage information")
    args = parser.parse_args()

    env = pike.Environment(watch=True, cache='.pike-cache')
    with pike.Graph('tests') as graph:
        runner = TestRunnerNode(args.coverage)
        pike.glob('pike', '*.py') | runner
    env.add(graph)
    env.run_forever(sleep=1)
Example #14
0
    def _run_test(self, settings):
        """ Run a simple pyramid app and check that serving files works """
        config = Configurator(settings=settings)
        config.include('pike')
        files = {
            'foo.html': b'<h1>hello world</h1>',
            'foo.js': b"alert('hello world');",
        }
        self.make_files(files)
        env = config.get_pike_env()
        with pike.Graph('assets') as graph:
            pike.glob('.', '*')
        env.add(graph)
        env.run_all()

        app = webtest.TestApp(config.make_wsgi_app())
        # Fetch a file
        response = app.get('/gen/foo.html')
        self.assertEqual(response.body, files['foo.html'])

        # Fetch a missing file
        response = app.get('/gen/foo.bar', expect_errors=True)
        self.assertEqual(response.status_code, 404)
Example #15
0
    def _run_test(self, config):
        """ Run a simple flask app and check that serving files works """
        import flask
        app = flask.Flask(__name__)
        app.config.update(config)
        files = {
            'foo.html': b'<h1>hello world</h1>',
            'foo.js': b"alert('hello world');",
        }
        self.make_files(files)
        env = pike.flaskme(app)
        with pike.Graph('assets') as graph:
            pike.glob('.', '*')
        env.add(graph)
        env.run_all()

        client = app.test_client()
        # Fetch a file
        response = client.get('/gen/foo.html')
        self.assertEqual(response.get_data(), files['foo.html'])

        # Fetch a missing file
        response = client.get('/gen/foo.bar')
        self.assertEqual(response.status_code, 404)
Example #16
0
 def test_multi_sink_explicit(self):
     """ Explicitly using the sink node fixes ambiguity errors """
     with Graph("g") as graph:
         pike.glob("a", "*") | graph.sink
         pike.glob("b", "*") | "in2" * graph.sink
Example #17
0
 def test_multi_sink(self):
     """ Ambiguous sink nodes cause validation error """
     with self.assertRaises(ValidationError):
         with Graph("g") as graph:
             pike.glob("a", "*")
             pike.glob("b", "*")