def testSimpleScopeByteString(self): scope_config = {sid("foo"): {vid("bar"): "BAR", vid("baz"): "BAZ"}} subst = interpolation.Substitution(var_config={}, scope_config=scope_config) self.assertEqual(subst.Substitute(b"%%foo.bar%% %%foo.baz%%"), b"BAR BAZ")
def testMultipleVarUnicodeString(self): var_config = {vid("foo"): "FOO", vid("bar"): "BAR", vid("baz"): "BAZ"} subst = interpolation.Substitution(var_config=var_config, scope_config={}) self.assertEqual(subst.Substitute("%%foo%% %%bar%% %%baz%%"), "FOO BAR BAZ")
def testMultipleVarByteString(self): var_config = {vid("foo"): 42, vid("bar"): "BAR", vid("baz"): 1337} subst = interpolation.Substitution(var_config=var_config, scope_config={}) self.assertEqual(subst.Substitute(b"%%foo%% %%bar%% %%baz%%"), b"42 BAR 1337")
def testVarAndScope(self): var_config = {vid("foo"): "FOO"} scope_config = {sid("quux"): {vid("bar"): "BAR", vid("baz"): "BAZ"}} subst = interpolation.Substitution(var_config=var_config, scope_config=scope_config) pattern = "%%foo%% %%quux.bar%% %%quux.baz%%" self.assertEqual(subst.Substitute(pattern), "FOO BAR BAZ")
def testInterpolationHappensSimultaneously(self): var_config = {vid("foo"): "%%bar%%", vid("bar"): "%%quux.norf%%"} scope_config = { sid("quux"): { vid("norf"): "%%foo%%", vid("thud"): "%%quux.norf%%" } } subst = interpolation.Substitution(var_config=var_config, scope_config=scope_config) pattern = "%%foo%% %%bar%% %%quux.norf%% %%quux.thud%%" output = "%%bar%% %%quux.norf%% %%foo%% %%quux.norf%%" self.assertEqual(subst.Substitute(pattern), output)
def testMultipleScopeByteString(self): scope_config = { sid("foo"): { vid("bar"): 2, vid("baz"): 3 }, sid("quux"): { vid("norf"): 5, vid("thud"): 7 }, } subst = interpolation.Substitution(var_config={}, scope_config=scope_config) pattern = b"%%foo.bar%% %%foo.baz%% %%quux.norf%% %%quux.thud%%" self.assertEqual(subst.Substitute(pattern), b"2 3 5 7")
def testMultipleScopeUnicodeString(self): scope_config = { sid("foo"): { vid("bar"): "BAR", vid("baz"): "BAZ" }, sid("quux"): { vid("norf"): "NORF", vid("thud"): "THUD" }, } subst = interpolation.Substitution(var_config={}, scope_config=scope_config) pattern = "%%foo.bar%% %%foo.baz%% %%quux.norf%% %%quux.thud%%" self.assertEqual(subst.Substitute(pattern), "BAR BAZ NORF THUD")
def testSimpleVarByteString(self): var_config = {vid("foo"): 42} subst = interpolation.Substitution(var_config=var_config, scope_config={}) self.assertEqual(subst.Substitute(b"%%foo%%"), b"42")
def testSimpleVarUnicodeString(self): var_config = {vid("foo"): 108} subst = interpolation.Substitution(var_config=var_config, scope_config={}) self.assertEqual(subst.Substitute("%%foo%%"), "108")
def testNoPlaceholdersByteString(self): subst = interpolation.Substitution(var_config={}, scope_config={}) self.assertEqual(subst.Substitute(b"FOOBARBAZ"), b"FOOBARBAZ")
def testNoPlaceholdersUnicodeString(self): subst = interpolation.Substitution(var_config={}, scope_config={}) self.assertEqual(subst.Substitute("foo bar baz"), "foo bar baz")
def testMultipleVariableOccurences(self): var_config = {vid("foo"): 42} subst = interpolation.Substitution(var_config=var_config, scope_config={}) self.assertEqual(subst.Substitute("%%foo%% %%foo%% %%foo%%"), "42 42 42")